Skip to content

fix(frontend): preserve redirect target through SSO login - #13270

Merged
SchrodingersGat merged 3 commits into
inventree:masterfrom
newAM:sso-redir-fix
Nov 14, 2026
Merged

SchrodingersGat merged 3 commits into
inventree:masterfrom
newAM:sso-redir-fix

Conversation

@newAM

@newAM newAM commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

The redirect target set by ProtectedRoute travels in react-router state, which does not survive the full page navigation through the identity provider. After the SSO round trip users always landed on /home.

Forward the target through the flow as a 'next' query param on the allauth callback URL instead, and recover it on the /logged-in page. Falls back to /home when no valid in-app path is present.


I have been using inventree with inventree-part-import, which provides a URL after adding a part. However I always landed on the home page, never the newly added part. This is my attempt to fix that behaviour.

@netlify

netlify Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 0ec9e06
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6af79b5015984dc64e6ada3d

@newAM
newAM marked this pull request as ready for review November 13, 2026 21:22
The redirect target set by ProtectedRoute travels in react-router state,
which does not survive the full page navigation through the identity
provider. After the SSO round trip users always landed on /home.

Forward the target through the flow as a 'next' query param on the
allauth callback URL instead, and recover it on the /logged-in page.
Falls back to /home when no valid in-app path is present.
@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed backport Apply this label to a PR to enable auto-backport action User Interface Related to the frontend / User Interface backport-to-1.7.x Apply this label to backport a PR to the 1.7.x branch labels Nov 13, 2026
@SchrodingersGat SchrodingersGat added this to the 1.8.0 milestone Nov 13, 2026
@SchrodingersGat

Copy link
Copy Markdown
Member

@newAM LGTM, thanks for the fix

@matmair can you please check this one too?

@newAM

newAM commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

I see there's 4 failing checks. I don't think they're related to my change, but maybe I'm not connecting the dots.

@matmair

matmair commented Nov 13, 2026

Copy link
Copy Markdown
Member

@newAM they are not, already working on a fix

@matmair

matmair commented Nov 13, 2026

Copy link
Copy Markdown
Member

fix in #13273; it looks like your code is not the cause for the failure here

// the way back. Forward it through the flow instead, appended to the
// callback URL allauth redirects the browser back to - LoggedIn.tsx
// picks the 'next' parameter back up once the login completes.
const next = `${redirect?.redirectUrl ?? ''}${redirect?.queryParams ?? ''}`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

against which sso provider did you test this? i am having issues getting this working with arzure ad via (custom) saml provider

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried it out with Kanidm, but I'm realizing there's gaps in my understanding, and therefore testing.

I tested with curl because that's what I've used in the past for SSO testing, and I had the script on-hand to navigate Kanidm with curl, but those webapps had little to no javascript in the frontend. My caveman curl approach worked... but missed that this doesn't work for the real case of a real web browser because the SSO flow is started by javascript.

I opened #13279 to fix this.

Sorry about that. My background is in embedded microcontrollers, still learning my way around frontend.

@matmair matmair left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this looks correct and I do not see a security issue here even after thinking a bit about it;

i would appreciate if you could extend the sso forntend test to also test this just to ensure this keeps on working.

Clean patch, great effort; thank you!

@SchrodingersGat
SchrodingersGat merged commit b9b4679 into inventree:master Nov 14, 2026
42 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
✅ 1.7.x

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

SchrodingersGat added a commit that referenced this pull request Nov 14, 2026
…13276)

The redirect target set by ProtectedRoute travels in react-router state,
which does not survive the full page navigation through the identity
provider. After the SSO round trip users always landed on /home.

Forward the target through the flow as a 'next' query param on the
allauth callback URL instead, and recover it on the /logged-in page.
Falls back to /home when no valid in-app path is present.



(cherry picked from commit b9b4679)

Co-authored-by: Alex Martens <[email protected]>
Co-authored-by: Matthias Mair <[email protected]>
Co-authored-by: Oliver <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Apply this label to a PR to enable auto-backport action backport-to-1.7.x Apply this label to backport a PR to the 1.7.x branch bug Identifies a bug which needs to be addressed User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants