Skip to content

Vaild OIDC redirect_uri from site root in path mode - #5555

Merged
mauromsl merged 2 commits into
r-v1.9.xfrom
b-5509-oidc-path-mode
Oct 8, 2026
Merged

mauromsl merged 2 commits into
r-v1.9.xfrom
b-5509-oidc-path-mode

Conversation

@ajrbyers

Copy link
Copy Markdown
Member

Closes #5509

Journals served in path mode set a script prefix of /<code>, which
leaked into every absolutify(request, reverse("oidc_authentication_callback"))
in mozilla-django-oidc. Identity providers exact-match redirect_uri
against registered callbacks, so logins from journal pages failed
(Entra AADSTS50011) and silent session refresh looped (AADSTS50196).

- Add JanewayOIDCAuthenticationRequestView, set as OIDC_AUTHENTICATE_CLASS,
  which resets the script prefix around the authorize request and, when
  no next url is supplied, returns users to the site they started on.
- Add opt-in JanewaySessionRefresh middleware which resets the prefix
  around the prompt=none re-auth redirect and also exempts the OIDC
  endpoints when reached under a journal prefix (the stock check uses
  request.path and caches exempt urls under the first request's prefix).
- Add regression tests driving both paths through real requests, and a
  query_parameter_from_url / login_with_expired_oidc_session test helper.

Closes #5509
@ajrbyers ajrbyers changed the title Vuild OIDC redirect_uri from site root in path mode Vaild OIDC redirect_uri from site root in path mode Oct 2, 2026
@ajrbyers
ajrbyers requested a review from mauromsl October 7, 2026 12:10

@mauromsl mauromsl 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.

Please, reconsider redirecting OIDC flow through the press, with a redirect to the user location at the end over monkey patching global request status (script prefix)

Comment thread src/utils/oidc.py Outdated
Comment on lines +48 to +60
# giving /<journal_code>/ in path mode and / at press level.
default_next = reverse("website_index")
prefix = get_script_prefix()
set_script_prefix("/")
try:
response = super().get(request)
finally:
set_script_prefix(prefix)

if not request.session.get("oidc_login_next"):
request.session["oidc_login_next"] = default_next

return response

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 monkeypatch is far from ideal. Can't we instead always redirect to the press OIDC view, and use a querystring parameter to redirect the user to where they came from? This is basically what we are pretending to do when delegating to OIDCAuthenticationRequestView via super.get() but withot control over any side effects of the mutation done via set_script_prefix("/")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, reworked in 0adbd38. Path-mode requests now redirect to the press-level /oidc/authenticate/ with ?next= set to the page the user started on, and the press-level view just calls super().get(). set_script_prefix is gone. One caveat: domain-mode sites keep their own session cookie, so they still start the login on their own domain.

Comment thread src/utils/oidc.py Outdated
Comment on lines +78 to +85
def process_request(self, request):
prefix = get_script_prefix()
set_script_prefix("/")
try:
return super().process_request(request)
finally:
set_script_prefix(prefix)

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.

above comments applies here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same commit: JanewaySessionRefresh is removed, so nothing changes the script prefix any more. Silent session refresh under a path prefix can be a follow-up if we need it.

@mauromsl mauromsl assigned ajrbyers and unassigned mauromsl Oct 7, 2026
@ajrbyers
ajrbyers requested a review from mauromsl October 8, 2026 12:19
@ajrbyers ajrbyers assigned mauromsl and unassigned ajrbyers Oct 8, 2026
@mauromsl
mauromsl merged commit 6762cf1 into r-v1.9.x Oct 8, 2026
4 checks passed
@mauromsl
mauromsl deleted the b-5509-oidc-path-mode branch October 8, 2026 12:25
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