8000 Preserve requested URLs through login by hartikainen · Pull Request #1053 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

Preserve requested URLs through login - #1053

Open
hartikainen wants to merge 1 commit into
mainfrom
fix/login-return-url
Open

hartikainen wants to merge 1 commit into
mainfrom
fix/login-return-url

Conversation

@hartikainen
@hartikainen hartikainen commented Oct 1, 2026 •
Copy link
Copy Markdown
Collaborator

I'm putting this out here as a proposed solution for #1052. This is fully Astra-coded and I haven't yet verified the changes myself beyond the unit tests.

The changes here wire the requested route through OAuth state so sign-in returns to the originally-requested page (including its query and fragment). It accepts only local absolute paths and bind the destination to the state cookie and falls back to /experiments when no valid destination is supplied.

Closes #1052.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements a mechanism to preserve and restore the user's requested destination path, query, and fragment across the OAuth2 login flow. On the frontend, the Angular authGuard and HomePage components are updated to pass the requested URL as a return_to query parameter to the login endpoint. On the backend, the Go OAuth2 package encodes this path into the OAuth state, validates that it is a safe local path, and redirects the user to it upon successful authentication. Feedback on the changes highlights a potential open redirect vulnerability in isLocalReturnPath where multi-slash paths (e.g., ///example.com) could bypass the local path check, and suggests adding corresponding test cases to prevent this security issue.

Comment thread pkg/auth/oauth2/redirect.go Resolved
Comment thread pkg/auth/oauth2/redirect_test.go Resolved
hartikainen added a commit that referenced this pull request Oct 1, 2026
Reject raw return paths beginning with `//` before parsing. Cover triple,
quadruple, and percent-encoded leading slashes in the validator and login
callback tests. The decoded-path check also rejects these inputs; the raw
check makes the restriction explicit at the input boundary.

Comment link: #1053 (comment)
Comment link: #1053 (comment)
@AntonTyb
AntonTyb commented Oct 2, 2026
Copy link
Copy Markdown
Collaborator

@hartikainen - thank you for the fix. ready for review?

@hartikainen
hartikainen marked this pull request as ready for review October 2, 2026 18:19
@github-actions
github-actions Bot requested a review from andrzejfudro October 2, 2026 18:19
hartikainen added a commit that referenced this pull request Oct 2, 2026
Reject raw return paths beginning with `//` before parsing. Cover triple,
quadruple, and percent-encoded leading slashes in the validator and login
callback tests. The decoded-path check also rejects these inputs; the raw
check makes the restriction explicit at the input boundary.

Comment link: #1053 (comment)
Comment link: #1053 (comment)
@hartikainen
hartikainen force-pushed the fix/login-return-url branch from bc8f921 to b99ce9f Compare October 2, 2026 21:22
andrzejfudro
andrzejfudro previously approved these changes Oct 5, 2026
@hartikainen
Copy link
Copy Markdown
Collaborator Author

This is now ready to go. @andrzejfudro, mind giving it another look? (I just updated the branch off of main.)

@hartikainen
hartikainen enabled auto-merge November 2, 2026 12:33
Carry the requested route through OAuth state so sign-in returns to the
original page, including its query and fragment. Accept only local
absolute paths and bind the destination to the state cookie. Fall back
to `/experiments` when no valid destination is supplied.

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.

[Feature]: Redirect user back to the original URL after login

3 participants

0