Skip to content

JITSU-302: close the return URL open redirect and compare tokens in constant time - #1660

Open
sahiltyagi-jitsu wants to merge 2 commits into
newjitsufrom
fix/jitsu-302-redirect-timing-safe
Open

sahiltyagi-jitsu wants to merge 2 commits into
newjitsufrom
fix/jitsu-302-redirect-timing-safe

Conversation

@sahiltyagi-jitsu

Copy link
Copy Markdown
Contributor

JITSU-302. Part of JITSU-250. This PR takes two of the items of the ticket; the others are separate changes.

Problem

  • Return URL. validateReturnUrl accepted any path that started with / and not //. Browsers read a backslash as a slash and drop tabs and newlines from a URL, so /\evil.example and /<tab>/evil.example mean //evil.example: after sign-in the user could be sent to another host. The links of the billing banners (isSafeLocation in BillingBanners.tsx) used the same rule.
  • Token compares. checkRawToken and checkHash in libs/juava compared with ===, and the SYNCCTL_AUTH_KEY check of /api/admin/sync-quota-check with !==. 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. validateReturnUrl and 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 with crypto.timingSafeEqual, so neither the content nor the length shows in the time. checkRawToken, checkHash and 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 whatever isLocalPath accepts resolves to this origin in the URL parser. It also shows that the attack is real: the parser resolves /\evil.example to evil.example.
  • security.test.ts (juava): safeEqual for equal, different and different-length strings, and that checkRawToken and checkHash go through crypto.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 timingSafeEqual tests 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

  • Console unit project: 59 files, 684 tests pass. juava: 76 tests pass. Console tsc, eslint and prettier are clean.
  • The sync-quota-check integration test passes against a real Postgres.

Not verified

  • The sign-in redirect was not run through a real OIDC provider; it is covered through the pure function and the URL parser.
  • BillingBanners.tsx has no test of its own; it calls the shared helper.
  • mcp-server/oauth.ts (PKCE challenge) and fb-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. No deploy:console label yet.

…r in a return URL, and compare tokens in constant time
jitsu-code-review[bot]
jitsu-code-review Bot previously approved these changes Nov 24, 2026

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 4a59ee5c6aaaa077cd5d0b3d9a00135ebdd82684

Reviewed the full diff and confirmed the string comparison regression with a focused Node check. Workspace lint and integration tests require dependencies absent from this checkout.

Comment thread libs/juava/src/security.ts Resolved
…the sync-quota-check test lint-clean and independent of the runner's environment

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 08e0acf25c171fabfaf739c71f15c1ee3023d985

Reviewed the full incremental diff and found no actionable defects. Direct Node.js checks passed for token equality, including lone surrogates. The console integration test was reviewed by inspection.

This branch has not been deployed

No deployments
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