Skip to content

fix(db-sync): the node server answers a websocket upgrade whose auth fails - #13692

Closed
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/db-sync-ws-upgrade-auth-error
Closed

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/db-sync-ws-upgrade-auth-error

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

A websocket upgrade to the Node sync server whose authentication fails with an error (a malformed bearer token such as x.y.z, or a JWKS fetch failure) is never answered: the socket is neither upgraded, refused nor closed, and stays open until the client gives up. The same failure on an HTTP request gets a 500 (node-server-returns-500-when-auth-claims-rejects-test).

Cause: the server's "upgrade" handler runs access-allowed? (which calls auth/auth-claims) and the readiness check in a promise chain with no catch. A token read as no user is dropped (allowed? is false), but a rejected auth-claims skips every branch, so nothing is written to the socket. Anyone can hold sockets open on the server this way without valid credentials; no graph data is reached.

Fix: the chain gets a catch that logs :db-sync/node-ws-upgrade-failed and answers the upgrade with a 500 (then closes the socket), unless the socket is already gone. reject-ws-upgrade! now writes the reason phrase for its status (it always wrote Conflict, which was right only for its one caller, the 409).

Test: logseq.db-sync.node-server-test/node-server-answers-ws-upgrade-when-auth-claims-rejects-test: with auth-claims rejecting (as the existing HTTP test does), a websocket upgrade to /sync/graph-x gets an HTTP 500. On master it gets no answer and the test fails; with the fix it passes, along with the rest of logseq.db-sync.node-server-test and logseq.db-sync.worker-handler-ws-test (12 tests, 0 failures). Lint as in CI for deps/db-sync and the app.

Found by mutation testing (triage of node/server.cljs).

@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-ws-upgrade-auth-error branch October 21, 2026 18:02
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