Skip to content

fix(db-sync): confine third-party OAuth tokens and harden the sync server - #13780

Closed
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/db-sync-security
Closed

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/db-sync-security

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

fix(db-sync): confine third-party OAuth tokens and harden the sync server

Security review follow-ups (H1, H3, M1-M4, L1, L2, L4, L5):

  • Third-party OAuth tokens (logseq/* scopes or additional Cognito client
    ids) are rejected on the native surface: /sync, /assets, /graphs, /e2ee,
    the PAT endpoint and the node WebSocket upgrade. The MCP code-mode guard
    checks the resolved URL origin and pathname.
  • Graph deletion requires a manager; /sync//admin/reset is 404 without
    the admin token; /internal/* tails are blocked in both dispatchers.
  • DB_SYNC_ALLOW_UNVERIFIED_JWT_CLAIMS falls back only on the JWKS-
    unreachable error; every other verification failure is a plain 401.
  • The x-graph-id header is gone; the sync path is authoritative.
  • Member removal closes the member's sockets on a new DO-internal route;
    expired tokens close their socket on the next message.
  • The DO routes the path exactly as received (no /sync prefix stripping),
    the node adapter blocks /semantic tails, and graph-e2ee is always set
    explicitly by dispatch.
  • Error responses carry no internal details (debug-*, error-detail).
  • Non-image asset types are served as attachment with nosniff; SVG gets a
    CSP sandbox. Plain-graph asset PUTs verify the declared checksum.
  • The node adapter no longer sends self-hosted users' tokens to
    api.logseq.com unless the issuer is Logseq's own pool.

Note: the auth-claims catch handler returns false instead of nil and
normalizes it, working around a promesa 11 bug: every nil resolution is
one shared promise, and a task that throws during its drain rejects the
other tasks of that drain.

…rver

Security review follow-ups (H1, H3, M1-M4, L1, L2, L4, L5):

- Third-party OAuth tokens (logseq/* scopes or additional Cognito client
  ids) are rejected on the native surface: /sync, /assets, /graphs, /e2ee,
  the PAT endpoint and the node WebSocket upgrade. The MCP code-mode guard
  checks the resolved URL origin and pathname.
- Graph deletion requires a manager; /sync/<g>/admin/reset is 404 without
  the admin token; /internal/* tails are blocked in both dispatchers.
- DB_SYNC_ALLOW_UNVERIFIED_JWT_CLAIMS falls back only on the JWKS-
  unreachable error; every other verification failure is a plain 401.
- The x-graph-id header is gone; the sync path is authoritative.
- Member removal closes the member's sockets on a new DO-internal route;
  expired tokens close their socket on the next message.
- The DO routes the path exactly as received (no /sync prefix stripping),
  the node adapter blocks /semantic tails, and graph-e2ee is always set
  explicitly by dispatch.
- Error responses carry no internal details (debug-*, error-detail).
- Non-image asset types are served as attachment with nosniff; SVG gets a
  CSP sandbox. Plain-graph asset PUTs verify the declared checksum.
- The node adapter no longer sends self-hosted users' tokens to
  api.logseq.com unless the issuer is Logseq's own pool.

Note: the auth-claims catch handler returns false instead of nil and
normalizes it, working around a promesa 11 bug: every nil resolution is
one shared promise, and a task that throws during its drain rejects the
other tasks of that drain.
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined with the other PRs that change the same files into #13781.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/db-sync-security branch October 21, 2026 18:01
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