Skip to content

✨ Feature(gui): configure server upload secret in settings - #1451

Merged
Molunerfinn merged 4 commits into
devfrom
feat-server-secret-setting
Oct 5, 2026
Merged

Molunerfinn merged 4 commits into
devfrom
feat-server-secret-setting

Conversation

@Molunerfinn

@Molunerfinn Molunerfinn commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Background

PicGo Core has long supported authenticating POST /upload on the built-in HTTP server, but the GUI had no setting for it: users had to edit settings.server.secret in the config file by hand or set the PICGO_SERVER_SECRET environment variable before launching PicGo.

How auth works in Core 3.1.0 (src/lib/Server/index.ts):

  • The secret is resolved from the listen() argument → PICGO_SERVER_SECRET → settings.server.secret. It is trimmed, and an empty value disables authentication.
  • Clients can send it as Authorization: Bearer <secret>, X-PicGo-Secret: <secret>, or ?secret= (logs a one-time warning).
  • Only POST /upload is protected; failures return 401.

Changes

  • Add a secret field below the port in the Set PicGo Server dialog. Like host and port, it is only shown while the server is enabled.
    • Masked by default with a show/hide toggle; it is masked again whenever the dialog closes.
    • Help text below the field explains the required request header and that leaving it empty disables authentication.
  • Save the trimmed value as settings.server.secret. The existing save flow already triggers server.restart(), and Core reads the secret from config on listen(), so no main-process change is needed and PICGO_SERVER_SECRET still takes precedence.
  • Add an optional secret to IServerConfig, the view type and SettingsServerConfig, with an empty default.
  • Keep secret in normalizeSettingsConfig. It previously copied only host, port and enable, so after a reload the dialog showed an empty secret, and saving the dialog again (e.g. after changing the port) would have silently cleared the secret and disabled authentication.
  • Add 5 keys to each of en / zh-CN / zh-TW / ja / ko; i18n.d.ts is regenerated by the build.
  • Add search keywords (secret / auth and their Chinese equivalents) to the server settings entry. The secret value itself is never added to the search index (unlike host and port values).
  • AGENTS.md:
    • Document that renderer config normalization is a whitelist, and list what must be updated when adding a persisted config field (shared types, renderer state type, default value, normalizer, plus a round-trip test).
    • Require English PR titles/descriptions and squash merges.

Validation

  • settings-dialog-server.spec.tsx (3 cases): saves the trimmed secret; clearing it saves an empty string; masked by default, can be revealed, and is masked again after reopening. Deliberately breaking the implementation (dropping trim(), not resetting the mask on close) makes all 3 fail; they pass again once restored.
  • settings-normalize.spec.ts (2 cases): the secret survives normalization, and falls back to an empty string when missing or not a string. Both failed before the normalizer fix.
  • End to end against Core 3.1.0, mimicking the GUI (save settings.server, then shutdown() + listen(port, host) without a secret argument):
Scenario Result
secret=first, no header 401
secret=first, Bearer first passes auth
changed to second and restarted, Bearer first 401
changed to second and restarted, Bearer second passes auth
cleared and restarted, no header passes (auth disabled)
  • Verified manually in pnpm dev that the saved secret takes effect; the "secret field empty after reopening" issue found there is fixed by the normalizer change above.
  • pnpm check (tsc, eslint, dpdm) passes and pnpm test passes (156 tests).

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.
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.
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.
@Molunerfinn
Molunerfinn merged commit 7a9bc23 into dev Oct 5, 2026
3 of 6 checks passed
@Molunerfinn
Molunerfinn deleted the feat-server-secret-setting branch October 5, 2026 12:26
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.

1 participant