Skip to content

server: generate a random secret by default so the local upload server requires auth - #1455

Open
carfeii wants to merge 7 commits into
Molunerfinn:masterfrom
carfeii:fix/server-default-secret
Open

carfeii wants to merge 7 commits into
Molunerfinn:masterfrom
carfeii:fix/server-default-secret

Conversation

@carfeii

@carfeii carfeii commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #1454.

ensureConfig() currently creates the local upload server's first-run configuration with no secret, and picgo-core treats a missing/empty secret as "authentication disabled" for every route including /upload. Combined with picgo-core's unrestricted CORS policy, this lets any web page the user visits make the server read an arbitrary local file and upload it through the user's configured image host, then read the resulting URL back cross-origin.

This generates a random 24-byte secret on first run and backfills one into any pre-existing config that was saved without one. picgo-core already reads settings.server.secret and enforces it on /upload whenever it is non-empty, so no change was needed outside this repo.

Verified: a cross-origin request that previously returned 200 with the exfiltrated file content now returns 401 Unauthorized once the generated secret is in place, while a pre-existing config that already has a user-set secret is left untouched.

Molunerfinn and others added 7 commits October 5, 2026 19:14
…erfinn#1449)

Mode is hydrated synchronously, but Verbosity / API version only show the saved values after the async refreshConfigSchema call resolves with the advanced-state choices. Both tests waited for Mode and then asserted the dependent fields synchronously, so on a slow CI runner they could still see the placeholder ("verbosity▼"). Move those assertions into waitFor.
…nn#1451)

* ✨ Feature(gui): configure server upload secret in settings

PicGo Core already supports authenticating `POST /upload` with a shared secret (`Authorization: Bearer <secret>`, `X-PicGo-Secret` or `?secret=`), resolved from `PICGO_SERVER_SECRET` or `settings.server.secret`, but the GUI offered no way to set it. Add a masked secret field with a show/hide toggle to the PicGo Server dialog, next to host and port.

The dialog saves the trimmed value as `settings.server.secret`; an empty value disables authentication. Saving already restarts the server, and Core reads the secret from config on `listen()`, so the main process needs no change and `PICGO_SERVER_SECRET` still takes precedence. The secret value is never added to the settings search index.

* 🐛 Fix(gui): keep server secret when normalizing settings

normalizeSettingsConfig only copied host, port and enable from `settings.server`, so after a reload the renderer state had no secret: the server dialog reopened with an empty secret field, and saving it again (e.g. after changing the port) would have silently cleared the secret and disabled authentication. Keep `secret` (falling back to an empty string) and cover it with a test.

* 📝 Docs: document renderer config normalizer whitelist in AGENTS.md

The server secret was dropped from renderer state because normalizeSettingsConfig only copies listed fields, and the server dialog re-saves the whole object. Record the rule for future changes: when adding a persisted config field, update the shared types, renderer state type, default value and normalizer, and add a round-trip normalizer test. Also give `settings.server.secret` an explicit empty default to follow that rule.

* 📝 Docs: require English PRs and squash merges in AGENTS.md
@Molunerfinn

Copy link
Copy Markdown
Owner

please change the target branch to dev

@Molunerfinn

Copy link
Copy Markdown
Owner

Thanks for the patch. Generating a secret does address the unauthenticated GUI server scenario, but I do not think we should automatically backfill one into existing configurations. That would break existing server integrations without an explicit user decision: requests that previously worked would begin returning 401 after an upgrade.

As noted above, please target dev. Against the current dev, the actual change is limited to src/main/server/index.ts; the secret setting and its UI support already exist there.

Please revise this toward an explicit GUI flow:

  1. On startup, when PicGo Server is running without an effective secret, show a warning explaining the security risk and the compatibility impact of enabling authentication.
  2. Allow dismissal without changing the secret. Offer a "Don't remind me again" checkbox and persist that preference only if selected.
  3. Use a clear affirmative action such as "Generate secret and enable authentication". Only after that action should PicGo generate and persist a random secret and apply it to the running server.
  4. After authentication is successfully enabled, show the generated token in a follow-up dialog with a copy button and instructions for configuring clients with Authorization: Bearer <secret> or X-PicGo-Secret: <secret>. Users should also be able to find the secret later in the existing server settings.

Please keep the renderer configuration synchronized after saving the secret, and include the new reminder preference in the shared types, defaults, and renderer normalizer so it survives a settings round trip. The current "leave empty to disable authentication" behavior should not silently turn into "generate a new secret" on restart.

Tests should cover dismissal leaving the secret unchanged, persistence of the reminder preference, explicit generation and activation, preservation of existing secrets, and authenticated/unauthenticated requests after enabling authentication. Please also add localized dialog text and usage guidance.

No Core behavior change is needed for this proposed GUI flow, since Core already provides the authentication mechanism. Users who decline authentication will still have the reported exposure, so the warning must clearly explain that tradeoff.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants