Repository navigation
JITSU-302: close the return URL open redirect and compare tokens in constant time - #1660
Open
sahiltyagi-jitsu wants to merge 2 commits into
Open
sahiltyagi-jitsu wants to merge 2 commits into
sahiltyagi-jitsu wants to merge 2 commits into
Conversation
…r in a return URL, and compare tokens in constant time
…the sync-quota-check test lint-clean and independent of the runner's environment
sahiltyagi-jitsu
dismissed
jitsu-code-review[bot]’s stale review
via
November 24, 2026 11:14
08e0acf
This branch has not been deployed
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.
JITSU-302. Part ofJITSU-250. This PR takes two of the items of the ticket; the others are separate changes.Problem
validateReturnUrlaccepted any path that started with/and not//. Browsers read a backslash as a slash and drop tabs and newlines from a URL, so/\evil.exampleand/<tab>/evil.examplemean//evil.example: after sign-in the user could be sent to another host. The links of the billing banners (isSafeLocationinBillingBanners.tsx) used the same rule.checkRawTokenandcheckHashinlibs/juavacompared with===, and theSYNCCTL_AUTH_KEYcheck of/api/admin/sync-quota-checkwith!==. Such a compare stops at the first different character, and its time tells a caller how many leading characters of a token were right.Change
isLocalPath(lib/auth-redirect.ts) is the one rule for a path on this origin: a single leading/, no backslash or control character, and it has to resolve to the same origin in the URL parser.validateReturnUrland the banner links use it. A path that is still accepted is unchanged, and the auth pages still return to/.safeEqual(libs/juava/src/security.ts) hashes both strings and compares the digests withcrypto.timingSafeEqual, so neither the content nor the length shows in the time.checkRawToken,checkHashand the sync-quota-check route use it. The hash format and the accepted tokens are unchanged.Tests
auth-redirect.test.ts(unit): the attacks above and more, absolute and scheme URLs, the valid paths, and an exhaustive check over every ASCII pair (/xy,/xyz,/xxy) that whateverisLocalPathaccepts resolves to this origin in the URL parser. It also shows that the attack is real: the parser resolves/\evil.exampletoevil.example.security.test.ts(juava):safeEqualfor equal, different and different-length strings, and thatcheckRawTokenandcheckHashgo throughcrypto.timingSafeEqual.sync-quota-check-auth.test.ts(integration): no key, wrong keys of the same, shorter and longer length, and the right key.The return URL tests and the
timingSafeEqualtests fail on the code before this change, on the assertion under test ("/\evil.example": expected true to be false; the spy is never called). A timing difference cannot be seen in a test, so the second kind checks the call, not the time. The sync-quota-check test passes before and after: it guards the behaviour of the swap, and fails when the check is made to always pass.Verified
tsc, eslint and prettier are clean.Not verified
BillingBanners.tsxhas no test of its own; it calls the shared helper.mcp-server/oauth.ts(PKCE challenge) andfb-auth/create-session.ts(CSRF double-submit) compare two values that the caller already holds, so they are left as they are.Release
Console only, no migration. The compares are in
libs/juava, which other services also build. Nodeploy:consolelabel yet.