fix(pwa): unbreak sign-out, and stop echoing $PUBLIC_ORIGIN in the CLI hint - #108
Merged
Conversation
…I hint Two bugs on the dashboard, both fixed by handing appBar/CLI_HINT the request. Sign-out was broken for everyone. csrfGuard rejects any POST whose _csrf does not match the mc_csrf cookie, and /auth/logout is a POST that is not on the exempt list, but the sign-out form carried no hidden field -- every click answered 403 "bad csrf token". appBar now takes the request rather than the user, because it needs the token as well as the identity. The field is written out instead of reusing csrfInput(): html.mjs is the view layer and imports nothing, and pulling in session.mjs would drag the database driver with it. The "Connect the CLI" snippet still printed $PUBLIC_ORIGIN, so users on app.logicsrc.com were told to point LOGICSRC_API at the generated Railway hostname. #105 added requestOrigin() for exactly this and fixed the device-flow URLs; the dashboard hint was missed. It now follows the request too, which is not a hardcode swap -- the same deployment answering on its Railway hostname still self-describes correctly. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two dashboard bugs, both fixed by handing
appBar/CLI_HINTthe request.1. Sign-out is broken for everyone
csrfGuardrejects any POST whose_csrfdoesn't match themc_csrfcookie, and/auth/logoutis a POST that isn't on the exempt list (/api/,/webhooks/,/cli/token,/cli/device/). The sign-out form carried no hidden field, so every click answered403 bad csrf token.This isn't host-specific — nobody could log out, on any domain.
appBarnow takes the request rather than the user, since it needs the token as well as the identity. The field is written out instead of reusingcsrfInput():html.mjsis the view layer and imports nothing, and pulling insession.mjswould drag the database driver along with it.2. The CLI hint still echoed
$PUBLIC_ORIGINUsers on
app.logicsrc.comwere told to pointLOGICSRC_APIat the generated Railway hostname. #105 addedrequestOrigin()for exactly this class of bug and fixed the device-flow URLs — the dashboard hint was missed. Its own comment names this symptom.Not a hardcode swap: the same deployment answering on its Railway hostname still self-describes correctly.
Verification
Ran the app locally with
PUBLIC_ORIGINdeliberately set to the Railway URL, to reproduce production:Logout, real round trip (
csrfGuardruns before auth, so this needs no login):POST /auth/logoutwith no_csrf→403 bad csrf token— the reported failure, reproducedPOST /auth/logoutwith the cookie's token →302 → /— what the fixed form now sendsDashboard, real render (seeded a session in the local DB,
NODE_ENV=productionsotrust proxyis on):Host: app.logicsrc.com→LOGICSRC_API=https://app.logicsrc.comHost: logicsrc-credentials-production.up.railway.app→ still that host<input type="hidden" name="_csrf" value="…">matching the cookieup.railway.appoccurrences left on the pageTests: 9/9 pass (
node --testinapps/pwa), including 4 new ones pinning the sign-out field, its placement inside the form, the no-token case, and escaping of the identity.Still worth doing separately
config.originis correct to keep for security decisions, and it is still wrong in production.PUBLIC_ORIGINis set to the Railway URL, which leaves:passkey.mjsexpectedOrigin(andrpID) — passkey login/registration onapp.logicsrc.comcannot succeed while these are pinned to the Railway host.credshare.mjsinvite links — invite emails embed${config.origin}/teams/accept?..., so they point at the Railway host.Both are a config fix, not code: set
PUBLIC_ORIGIN=https://app.logicsrc.comon Railway. Note that changes the WebAuthn RP ID, so any passkey registered under the Railway host stops working and has to be re-registered.🤖 Generated with Claude Code