Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
09a9ca1
fix: preserve oidc deep links across callback storage
seonghobae Aug 20, 2026
f7d11e3
docs: avoid oidc adr number collision
seonghobae Aug 20, 2026
e0dbc38
docs: align OIDC ADR heading
seonghobae Aug 20, 2026
f922322
Merge remote-tracking branch 'origin/feat/analysis-run-name-evidence-…
seonghobae Aug 20, 2026
fc7969e
Merge remote-tracking branch 'origin/feat/analysis-run-name-evidence-…
seonghobae Aug 20, 2026
2d7f899
fix: bound OIDC return state parsing
seonghobae Aug 20, 2026
3a32312
Merge remote-tracking branch 'origin/feat/analysis-run-name-evidence-…
seonghobae Aug 20, 2026
d8b7eef
Merge remote-tracking branch 'origin/feat/analysis-run-name-evidence-…
seonghobae Aug 21, 2026
4e40e26
Merge remote-tracking branch 'origin/feat/analysis-run-name-evidence-…
seonghobae Aug 21, 2026
dab3994
fix: reject unsafe OIDC return paths
seonghobae Aug 21, 2026
b478f32
Merge latest parent into OIDC deep-link safety
seonghobae Aug 21, 2026
5c42aa2
Merge commit 'f5e23b5da8dbde4a696568731d649c24a6b12bbe' into HEAD
seonghobae Aug 21, 2026
bcd17a4
Merge remote-tracking branch 'origin/feat/analysis-run-name-evidence-…
seonghobae Aug 21, 2026
a5ca5c3
Merge remote-tracking branch 'origin/fix/oidc-deep-link-locale' into …
seonghobae Aug 21, 2026
2e0698f
Merge remote-tracking branch 'origin/fix/oidc-deep-link-locale' into …
seonghobae Aug 21, 2026
1e7eb26
Merge commit 'c8dcc27b2ae5db90a49397f4005d53b3350e532c' into HEAD
seonghobae Aug 21, 2026
08d7f95
Merge branch 'feat/analysis-run-name-evidence-lineage' of https://git…
seonghobae Aug 21, 2026
dd9c3a8
fix: render buyer-facing image evidence (#307)
seonghobae Aug 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/adr/0109-oidc-deep-link-state-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ADR 0109: Recover authenticated deep links across OIDC callback contexts

- Status: Accepted
- Date: 2026-08-20
- Depends on: [0069](0069-member-locale-preference.md), [0028](0028-keyverse-oidc-provider.md)

## Context

The Buyer can be opened directly at `/?post=<id>`. The OIDC provider callback
may omit application state or complete in a browser context where the original
tab's `sessionStorage` is not available. Falling back to `/` loses the post
deep link and presents the unauthenticated language/login surface again, even
when the member's OIDC session is otherwise valid.

## Decision

- Keep the OIDC `state.returnUrl` as the first recovery source.
- Persist the same validated same-origin path in both `sessionStorage` and
`localStorage` before redirecting to OIDC. `localStorage` is only a bounded
recovery fallback, not an authentication or authorization store.
- On callback, remove the key from both stores and use session storage before
local storage. Reject external and protocol-relative URLs.
- Keep member language preference account-scoped in
`user_account.preferred_locale`; this ADR does not move locale state into the
post URL, browser storage, or a `user_account + post_id` key.

## Consequences

Opening a shared post link survives a missing OIDC state payload or a changed
storage context without losing the post. A stale internal return path is
removed at callback, and authorization still comes only from the authenticated
OIDC token and backend ABAC checks.
13 changes: 12 additions & 1 deletion frontend/src/oidcReturnUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
} from "./oidcReturnUrl";

describe("OIDC return URL handling", () => {
beforeEach(() => window.sessionStorage.clear());
beforeEach(() => {
window.sessionStorage.clear();
window.localStorage.clear();
});

it("keeps a post deep link and rejects external destinations", () => {
expect(returnUrlFromLocation({ pathname: "/", search: "?post=abc", hash: "" })).toBe(
Expand All @@ -22,5 +25,13 @@ describe("OIDC return URL handling", () => {
rememberOidcReturnUrl("/?post=stored-again");
expect(restoreOidcReturnUrl('{"returnUrl":"/?post=from-json"}')).toBe("/?post=from-json");
expect(window.sessionStorage.getItem("lineageweave.oidc.returnUrl")).toBeNull();
expect(window.localStorage.getItem("lineageweave.oidc.returnUrl")).toBeNull();
});

it("restores a deep link from local storage when session storage is empty", () => {
window.localStorage.setItem("lineageweave.oidc.returnUrl", "/?post=from-local-storage");

expect(restoreOidcReturnUrl(undefined)).toBe("/?post=from-local-storage");
expect(window.localStorage.getItem("lineageweave.oidc.returnUrl")).toBeNull();
});
});
19 changes: 16 additions & 3 deletions frontend/src/oidcReturnUrl.ts

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Shared localStorage key can recover the wrong deep link across concurrent logins

rememberOidcReturnUrl now also writes the return path to window.localStorage under a single fixed key lineageweave.oidc.returnUrl (oidcReturnUrl.ts), and restoreOidcReturnUrl falls back to it (oidcReturnUrl.ts). localStorage is shared across all tabs of the origin, so if a user initiates login from tab A at /?post=A and then from tab B at /?post=B, tab B overwrites the shared key. If tab A's OIDC callback completes in a context where its per-tab sessionStorage is unavailable (exactly the cross-context recovery scenario this PR targets), it will read /?post=B from localStorage and recover the wrong post. Session storage is preferred first (:74) which mitigates the common same-tab case, and the more reliable source state.returnUrl is preferred over both, so impact is limited to the concurrent-login-with-lost-session edge case. Not flagged as a bug because it is an inherent tradeoff of a single-key shared store and the primary recovery path (OIDC state) is unaffected, but worth confirming this edge case is acceptable.

(Refers to this code)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Single-JSON-encoded safe string is now rejected (behavior change)

The previous recursive implementation would accept a state that was a JSON-encoded plain string of a safe path (e.g. state = '"/?post=x"'): it parsed once to the string, recursed, failed the second parse, and returned the safe path. The new single-parse implementation (oidcReturnUrl.ts) parses once, gets a string, then fails the typeof candidate !== "object" check at line 44 and returns "". This is an intentional narrowing per the PR's stated goal (parse at most once, only accept a direct path or one bounded object), so it is not a bug, but it is a genuine behavioral change for any provider that encoded state that way.

(Refers to this code)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: localStorage fallback staleness is bounded and acceptable

The new localStorage recovery path in oidcReturnUrl.ts persists across tabs and browser restarts, unlike the per-tab sessionStorage. I considered whether a stale return path could be applied incorrectly, but concluded it is safe: on callback both stores are cleared unconditionally regardless of which source wins, the OIDC state.returnUrl takes priority over storage, and the login button (App.tsx:4565-4567) always overwrites both stores with the current path before redirecting. So a leftover value from an abandoned flow gets overwritten on the next login. The ADR (0109-oidc-deep-link-state-recovery.md) also explicitly documents this as a bounded, non-authoritative recovery fallback.

(Refers to this code)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export function rememberOidcReturnUrl(value: string): void {
} catch {
// OIDC state remains the fallback when session storage is unavailable.
}
try {
window.localStorage.setItem(OIDC_RETURN_URL_STORAGE_KEY, value);
} catch {
// The OIDC state and session storage remain the fallbacks.
}
}

function stateReturnUrl(state: unknown): string {
Expand All @@ -35,15 +40,23 @@ function stateReturnUrl(state: unknown): string {

export function restoreOidcReturnUrl(state: unknown): string {
const fromState = stateReturnUrl(state);
let stored = "";
let sessionStored = "";
let localStored = "";
try {
stored = window.sessionStorage.getItem(OIDC_RETURN_URL_STORAGE_KEY) ?? "";
sessionStored = window.sessionStorage.getItem(OIDC_RETURN_URL_STORAGE_KEY) ?? "";
window.sessionStorage.removeItem(OIDC_RETURN_URL_STORAGE_KEY);
} catch {
// Fall through to local storage or the current path.
}
try {
localStored = window.localStorage.getItem(OIDC_RETURN_URL_STORAGE_KEY) ?? "";
window.localStorage.removeItem(OIDC_RETURN_URL_STORAGE_KEY);
} catch {
// Fall through to the current path.
}
if (fromState) return fromState;
if (isSafeReturnUrl(stored)) return stored;
if (isSafeReturnUrl(sessionStored)) return sessionStored;
if (isSafeReturnUrl(localStored)) return localStored;
return new URLSearchParams(window.location.search).has("post")
? returnUrlFromLocation()
: window.location.pathname;
Expand Down
Loading