Skip to content

Security: path prefix bypass, unsanitized link href, OAuth state validation gaps #1669

Open

Description

@Ikram-4

Security: multiple validation gaps (path prefix, link href sanitization, OAuth state)

Hi maintainers, reporting 3 validation gaps found by static review + isolated logic reproduction (no live exploitation). No PoC included. Happy to move to private advisories if preferred (no SECURITY.md found).

1. Local-mode path check allows sibling-prefix paths + unauthenticated handler

Vulnerability: Prefix check without directory boundary.
Files:

  • packages/keystatic/src/api/api-node.ts:129-135 (getIsPathValid uses filepath.startsWith(x) without x + '/' check)
  • packages/keystatic/src/api/api-node.ts:91-112,175-223 (localModeApiHandler / update / blob / tree check only no-cors / content-type headers, no auth)
  • packages/keystatic/src/api/read-local.ts:110-140, packages/keystatic/src/app/tree-key.tsx:67-82, packages/keystatic/src/app/path-utils.ts:5-7 (allowed dirs have no trailing slash, e.g. posts)
  • packages/keystatic/src/api/generic.ts:85-94 (local mode returned with no NODE_ENV gate)
    Impact: A path like posts-evil/... passes when only posts is allowed; with storage:{kind:'local'} (default in templates) the API allows file read/write/delete within base directory without authentication if the endpoint is reachable.
    Mitigation: Require filepath === dir || filepath.startsWith(dir + '/'), resolve + contain final path under baseDirectory (path.relative), deny symlinks, and gate local API to development/loopback or add authentication.

2. DocumentRenderer renders link href without sanitization

Vulnerability: Stored javascript: URL rendered verbatim.
Files:

  • packages/keystatic/src/renderer.tsx:261-266 (<renderers.inline.link href={node.href}>, default link: 'a' at :85, no sanitizeUrl/isValidURL)
  • packages/keystatic/src/form/fields/document/DocumentEditor/pasting/html.ts:153-161 + pasting/utils.ts:26-37 (paste stores any href, no validation)
  • packages/keystatic/src/form/fields/document/DocumentEditor/isValidURL.ts:1-5 (correct guard exists but only editor-side)
  • packages/keystatic/src/api/generic.ts:264-272 vs :274-289 (access-token cookie without HttpOnly, refresh with HttpOnly) + packages/keystatic/src/app/auth.ts:16-17 (client reads via document.cookie)
    Impact: Attacker-authored javascript: link persisted in document content renders as live <a href="javascript:..."> for consumers using DocumentRenderer; click executes JS in site origin which can read the non-HttpOnly GitHub access token.
    Mitigation: Validate/sanitize href at ingest and at render (e.g. sanitizeUrl/allowlist http(s)/mailto/tel/relative), and set HttpOnly on access-token cookie or move token out of cookie reach.

3. GitHub OAuth callback does not validate state + redirect_uri follows Host headers

Vulnerability: Missing OAuth CSRF binding.
Files:

  • packages/keystatic/src/api/generic.ts:216-255 (callback never rejects missing/mismatched state, exchanges code unconditionally; state==='close' at :248-253 also exchanges)
  • packages/keystatic/src/api/generic.ts:363-398 (login sends no state/cookie when from==='/' at :380-382; state only used for from lookup via ks-<state> cookie at :222-226)
  • packages/next/src/api.tsx:17-20 + packages/keystatic/src/api/generic.ts:367-378 (redirect_uri=${reqUrl.origin}/... built from x-forwarded-host/host)
  • packages/keystatic/src/api/generic.ts:32-33 (regex gates from for open-redirect, but not CSRF)
    Impact: Attacker code can be exchanged in victim browser (login CSRF, victim session bound to attacker authorization); redirect_uri origin follows attacker-influenced headers where deployments trust them.
    Mitigation: Always generate/send/verify state (reject missing/mismatched with 401 before token exchange, including from==='/' and close flows), and build redirect_uri from configured absolute URL with Host allowlist instead of request headers.

Versions checked: @keystatic/core 0.6.9 / main (Nov 2026). No existing GHSA found for these.

Activity

  1. tynianov1 commented on Nov 20, 2026

    @tynianov1

    Opened three PRs for the items in this issue:

    Each one is independent and has tests. Happy to adjust anything.

  2. Ikram-4 commented on Nov 23, 2026

    @Ikram-4
    Author

    @tynianov1 i was wondering if they're any security intern position open in your organization,I'm interested in your organization... The work which you guys are doing is great.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions