Skip to content

CLARIN-DSpace v9/Derive the temporary auth cookie path from dspace.server.url - #1490

Open
milanmajchrak wants to merge 4 commits into
dtq-dev-93from
ufal/fix-authn-cookie-path-9-base
Open

milanmajchrak wants to merge 4 commits into
dtq-dev-93from
ufal/fix-authn-cookie-path-9-base

Conversation

@milanmajchrak

@milanmajchrak milanmajchrak commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

References

No dtq-dev source: 7.x (origin/dtq-dev) sets no path on this cookie, so the bug is 9-base only. Vanilla has the same hardcoded path on dspace-9.3 and main (commit 551eed8, "Add SAML login filter"); upstream candidate.
Found on a v9 test instance where the REST API runs under /repository/server.

Description

The temporary Authorization-cookie used by the Shibboleth, OIDC, ORCID and SAML login was always issued with Path=/server/api/authn, so under another context path the browser never sends it to /api/authn/login and the external login ends as anonymous. The path now comes from dspace.server.url, for the cookie and for its removal.

Instructions for Reviewers

List of changes in this PR:

  • JWTTokenRestAuthenticationServiceImpl: new getAuthorizationCookiePath() returns the path of dspace.server.url (raw, without a trailing slash) plus /api/authn. addTokenToResponse uses it instead of the constant, and invalidateAuthenticationCookie now sets the same path (it had none, so the browser could keep the old cookie). The login callbacks build their URLs from the same property, so it also works behind a proxy that strips the prefix.
  • AuthenticationRestControllerIT: new testShibAuthCookiePathFollowsServerUrl runs the Shibboleth flow for dspace.server.url ending in /server, /server/, /repository/server and /caf%C3%A9/server, also with a servlet context path other than the public one, and checks the path on the issued cookie and on the one /login sends back to remove it. testStatusShibAuthenticatedWithCookie now also checks Path=/api/authn for the test dspace.server.url (http://localhost).

How to test:

  • Run AuthenticationRestControllerIT. The new test fails on the old code (Path=/server/api/authn).
  • On an HTTPS instance behind a path prefix (e.g. /repository/server) with an external IdP, log in with Shibboleth or ORCID and watch the network tab: the redirect back from the provider sets Authorization-cookie with Path=/repository/server/api/authn, and the following POST /api/authn/login answers 200 with an Authorization header. Before the fix the cookie path was /server/api/authn, the browser did not send it, and the user stayed anonymous. Plain HTTP cannot show this: the cookie is Secure; SameSite=None.
  • An instance with the default /server context behaves as before: Path=/server/api/authn.

Codex review (gpt-6.2-sol, high), 3 rounds: 3 findings fixed (path from dspace.server.url instead of the servlet context, trailing slash, percent escapes kept). The last round found 2, not changed in this PR: a literal non-ASCII character or a ../ segment written into dspace.server.url.

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & integration tests). Exceptions may be made if previously agreed upon.
  • My PR passes Checkstyle validation based on the Code Style Guide.
  • My PR includes Javadoc for all new (or modified) public methods and classes. It also includes Javadoc for large or complex private methods.
  • My PR passes all tests and includes new/updated Unit or Integration Tests based on the Code Testing Guide.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in any pom.xml), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR modifies REST API endpoints, I've opened a separate REST Contract PR related to this change.
  • If my PR includes new configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

🤖 Generated with Claude Code

The cookie was always issued with Path=/server/api/authn, so under
another context path (e.g. /repository/server) the browser never sent
it to /api/authn/login and the Shibboleth/OIDC/ORCID/SAML login ended
as anonymous. The removal cookie now carries the same path.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@jr-rk

jr-rk commented Oct 29, 2026 •

Copy link
Copy Markdown

Upstream already has an open PR for this bug: DSpace#11753. It derives the cookie path from dspace.server.url instead of request.getContextPath() like our variant. Upstream triage prefers this approach.

We opened a PR against the author's branch with the parts of this PR that fit that design: an integration test that fails without the fix, and the same Path when the cookie is invalidated. The decision is up to the author: vtThomaz#1

Upstream duplicates (all open, no review):

@milanmajchrak
milanmajchrak changed the base branch from dtq-dev-9-base to dtq-dev-93 November 17, 2026 15:57
milanmajchrak and others added 3 commits November 26, 2026 19:27
The login callbacks and the UI use dspace.server.url, so the cookie path follows
it also when the servlet context path is different, e.g. behind a proxy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@milanmajchrak milanmajchrak changed the title CLARIN-DSpace v9/Derive the temporary auth cookie path from the request context path CLARIN-DSpace v9/Derive the temporary auth cookie path from dspace.server.url Nov 26, 2026

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.

2 participants