← 输入框|github.com|刷新
Skip to content

[web-console] Keep the OIDC code and state out of the referrer after login - #7912

Merged
Karakatiza666 merged 1 commit into
mainfrom
oauth-callback-referrer
Nov 11, 2026
Merged

Karakatiza666 merged 1 commit into
mainfrom
oauth-callback-referrer

Conversation

@Karakatiza666

@Karakatiza666 Karakatiza666 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

After the OIDC code exchange, /auth/callback/ page redirected the user to / (home page) while its URL still held ?code=...&state=.... The new page got that URL as document.referrer. The PostHog and ConceptualHQ scripts sent it to third parties as referrer and $initial_referrer.

The code is single-use, PKCE-bound and already redeemed when it is sent, so it cannot be replayed. But authentication data must not go to analytics vendors.

Fix

Change Location
leaveOidcCallback() removes the query and fragment with history.replaceState, then navigates with location.replace. src/lib/services/auth.ts, called from src/routes/+layout.ts
<meta name="referrer" content="strict-origin">, so that pages of the console get only the origin as the referrer. Referrers from other sites do not change, because the linking site's policy controls them. src/app.html
The analytics scripts do not start on the callback page, whose URL holds the code and state. Only a session that is still valid can reach this case. initializeConfigDependencies in src/routes/+layout.ts

The PR also adds /.tmp/ to .gitignore for local scratch files.

Tests

Test Checks Fails without the fix
auth.spec.ts The URL at the moment of navigation has no query or fragment, for 5 URL forms. isOidcCallbackPage matches only the callback path. Yes, checked with mutations
layout.spec.ts The layout leaves the callback page with a clean URL. Analytics do not start on the callback page, and they do start on /. Yes, checked with mutations
tests/auth/oidcCallback.e2e.ts After a real login through the dummy OIDC provider, document.referrer is the console origin. Yes. On a build without the fix, the test received http://localhost:8095/auth/callback/?code=...&state=...

Run locally against a manager with OIDC:

  • vitest --project server: 525 passed
  • test-e2e-auth: the new test, homeDemos and logout passed. The 3 signup.e2e.ts tests failed locally in the same way on a build without this change, so the cause is the local setup. CI runs them on the Docker image.

Not in this PR

  • Users who logged in before this fix keep the old referrer in PostHog's $initial_person_info (localStorage and cookie) until they log out.

…login

After the code exchange, the callback page went to `/` with a full page
load while its URL still held `?code=...&state=...`. The new page got
that URL as `document.referrer`, and the PostHog and ConceptualHQ scripts
sent it to third parties as `referrer` and `$initial_referrer`.

- Remove the query and fragment from the callback URL before the
  navigation, and navigate with `location.replace`.
- Set `<meta name="referrer" content="strict-origin">`, so that pages of
  the console get only the origin as the referrer.
- Do not start the analytics scripts on the callback page, whose URL
  holds the code and state.

Also ignore the local `/.tmp/` scratch directory.
@mythical-fred-oss

Copy link
Copy Markdown
Contributor

LGTM

Ran Result
vitest --project server on auth.spec.ts and layout.spec.ts 25/25 passed
Mutation: drop the !isOidcCallbackPage() guard 1 test fails
Mutation: drop history.replaceState 5 tests fail
bun run check (svelte-check) 0 errors
pre-commit run --files <changed> passed
oidcCallback.e2e.ts not run (needs a manager with OIDC)

Gates: tests cover each part of the fix, the e2e test has no sleeps, and there are no deps, docs or breaking changes involved. I also checked that skipping analytics on the callback page does not lose the signin event: reportLogin returns early while no backend is initialized, so / still reports the login. The compositions/auth.ts → services/auth.ts import adds no cycle.

@Karakatiza666
Karakatiza666 added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit 827dd11 Nov 11, 2026
3 checks passed
@Karakatiza666
Karakatiza666 deleted the oauth-callback-referrer branch November 11, 2026 09:18
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.

2 participants