Skip to content

Security hardening: git SSRF, rate limits, CSRF, transfer links - #124

Merged
johnwmail merged 4 commits into
mainfrom
security/hardening-2026-12
Dec 3, 2026
Merged

johnwmail merged 4 commits into
mainfrom
security/hardening-2026-12

Conversation

@johnwmail

Copy link
Copy Markdown
Owner

Summary

Security review of main (7db4994) and fixes for the verified findings.

Backend

  • Git SSRF: the remote address policy is now enforced when connecting (HTTP dial control, SSH host-key callback), so DNS rebinding and redirects to private addresses are blocked. URL validation is stricter (scp host, whitespace/backslash, endpoint parse check), and the stored URL is re-validated on every push/pull.
  • Git credentials are no longer cached on the server: /git/session is removed; push/pull require the token in the request body. The dead toggle-sync route is removed too.
  • Git ops: per-account repo lock, context-aware clone/push with timeouts, .gpg-id read as a regular file only (no symlinks), re-init only on an empty remote, host-key fingerprint format validation.
  • Rate limiting: validate the fingerprint before using it as a key, check the IP budget first, group IPv6 by /64, authenticate key-transfer requests before limiting. New shared budget for endpoints that re-verify the login password (password change, account delete, TOTP setup/confirm, passkey add/remove), so a stolen session can't be used to brute-force the password.
  • CSRF exemptions match exact login paths (previously any path ending in /login, e.g. an entry named .../login, skipped CSRF in cookie mode).
  • Session check fails closed: a token for a deleted account (or a DB error) no longer grants access.
  • Size limits: oversized entries return 413 instead of being silently truncated (which corrupted the ciphertext). The tar import caps the whole decompressed stream, including skipped entries.
  • WebAuthn: challenge expiry stored in UTC (fixes failures on non-UTC hosts); logins with a clone warning are rejected.
  • SQLite: pragmas (foreign keys, busy timeout, secure delete, trusted_schema) are applied to every pooled connection; in-memory DBs use a single connection (fixes "no such table" errors with DB_PATH=:memory:).
  • JWT_SECRET placeholders (including the shipped example values) are rejected.

Frontend

  • Transfer links are validated (https server URL, fingerprint/token format). A server on another origin must be confirmed before the login password is sent there.
  • Pairing codes must be at least 8 characters.
  • Settings logout / account delete / password change now revoke the server session before clearing local state.
  • Entry path segments are URL-encoded.
  • The clipboard wipe survives component unmount; decrypted text from the Encrypt tool is wiped too.

Ops / docs

  • .dockerignore excludes env files, databases and keys in any directory.
  • OpenBSD relayd sets X-Forwarded-For/X-Forwarded-Proto; example env sets TRUSTED_PROXIES=127.0.0.1 (otherwise all clients share one rate-limit budget).
  • Release/deploy workflows use persist-credentials: false; wrangler is pinned.

Test plan

  • go fmt, go vet, golangci-lint run (0 issues), go test ./... (also with TZ=Asia/Hong_Kong)
  • npm run typecheck, npm run build, vitest (148 passed)
  • Playwright, all CI phases locally: rate limit (3), protected incl. git sync (67), registration open (6) / protected (8) / disabled (2)

rdu64 and others added 3 commits December 3, 2026 15:09
- Git: enforce the remote address policy at connect time (HTTP dial
  control and SSH host-key callback), stricter URL/scp host validation,
  re-validate the stored URL on push/pull, per-account repo lock,
  context-aware clone/push with timeouts, read .gpg-id as a regular file
  only, validate trusted host-key fingerprints.
- Remove the server-side git token cache and /git/session; push/pull
  require the token in the request body. Remove dead toggle-sync route.
- Rate limiting: validate the fingerprint before keying, check IP first,
  group IPv6 by /64, authenticate key-transfer before limiting, and add a
  shared budget for endpoints that re-verify the login password.
- CSRF exemptions match exact login paths only.
- Fail closed when session info cannot be loaded (deleted account).
- Reject oversized entries with 413 instead of truncating; cap the
  decompressed tar stream including skipped entries.
- WebAuthn: store challenge expiry in UTC, reject clone warnings.
- SQLite: apply pragmas to every pooled connection; single connection
  for in-memory databases.
- Reject JWT_SECRET placeholders, including the shipped examples.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Validate transfer links (https server URL, fingerprint and token
  format) and require confirmation before sending the login password to
  a server on another origin.
- Require pairing codes of at least 8 characters.
- Log out on the server before clearing the local session in Settings.
- Encode entry path segments in API URLs.
- Keep the clipboard wipe timer alive after the component unmounts and
  wipe decrypted text copied from the Encrypt/Decrypt tool.
- Send git credentials only with push/pull; drop setGitSession.

Co-authored-by: Cursor <cursoragent@cursor.com>
- .dockerignore: exclude env files, databases and keys in any directory.
- OpenBSD: set X-Forwarded-For/Proto in relayd and TRUSTED_PROXIES so
  rate limits are per client, not per proxy.
- Release/deploy workflows: persist-credentials: false; pin wrangler.
- README: update git sync endpoints.

Co-authored-by: Cursor <cursoragent@cursor.com>
…docs (#125)

* Device transfer v2: link secret in URL fragment, HKDF key separation, approval secret

- Mix a random link secret (URL fragment, never sent to a server) into the
  PBKDF2 input so the pairing code cannot be brute-forced offline from the
  server-held ciphertext.
- Derive separate AES-GCM and HMAC keys with HKDF (no key reuse for the proof).
- Envelope fetch is now POST and requires the one-time link token.
- Approve/deny require a secret only the creating device holds (hash uploaded).
- v1 envelopes/links are rejected; create a new link after upgrading.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Harden proxy trust, audit log, registration, TOTP, git clones and sync rate

- X-Forwarded-Proto is only honoured from TRUSTED_PROXIES.
- Audit log retention/pruning (AUDIT_RETENTION_DAYS, AUDIT_MAX_ROWS_PER_ACCOUNT)
  and unknown-account logins no longer create unbounded rows.
- Global registration-code failure counter (429 when locked).
- Atomic TOTP replay claim; minimum TOTP secret length.
- Shallow clones with size/file-count watchdog (GIT_MAX_REPO_MB).
- Per-account push/pull budget (GIT_SYNC_RATE_LIMIT).

Co-authored-by: Cursor <cursoragent@cursor.com>

* Optional entry signing and Argon2id key protection

- Sign-then-encrypt entries with the PGP key (opt-in per device); a present but
  invalid signature blocks the entry, unsigned entries are flagged when
  signing is on. Settings: toggle + 'Sign all entries'.
- Opt-in Argon2id S2K when changing the PGP passphrase (shows current mode).
- Unit + E2E tests.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Pages _headers, loopback compose bind, test hooks only in E2E builds

- frontend/public/_headers: CSP and security headers for Cloudflare Pages.
- CSP allows 'wasm-unsafe-eval' (Argon2id key unlock needs WebAssembly).
- docker-compose publishes on 127.0.0.1 by default (BIND_ADDRESS/HOST_PORT).
- window.__webpass only exists in VITE_E2E builds; CI checks the prod bundle.
- Server does not serve _headers/.gitkeep.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Docs: transfer v2, entry signing, Argon2id, new env vars, upgrade notes

README, AGENTS.md, CONTRIBUTING.md, .env.example and the OpenBSD env example
describe the new behaviour, limits, E2E build flavour and compatibility.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: rdu64 <rdu64@arm64.dev>
Co-authored-by: Cursor <cursoragent@cursor.com>
@johnwmail
johnwmail merged commit 4cc3a35 into main Dec 3, 2026
16 checks passed
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