Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(user): regenerate session id on Apache/SSO login - #65477

Open
jaykijay wants to merge 1 commit into
nextcloud:masterfrom
jaykijay:fix/apache-login-session-fixation
Open

jaykijay wants to merge 1 commit into
nextcloud:masterfrom
jaykijay:fix/apache-login-session-fixation

Conversation

@jaykijay

Copy link
Copy Markdown

Summary

Security-relevant fix (session fixation on the Apache/SSO login path).

Since #64582, OC_User::loginWithApache() calls completeLogin() with regenerateSessionId: false and creates the session token before completeLogin(), binding it to the pre-authentication session id. That removed the only session-id regeneration on the IApacheBackend path: a session id that already existed before authentication (e.g. initialized by a prior visitor of the login page) survives into the authenticated session. Apache/SSO logins also skip 2FA by design, so a fixated session is fully authenticated.

The reason #64582 disabled the regeneration is understandable: regenerating inside completeLogin() would orphan the just-created session token (plain regenerateId() does not re-bind tokens). This PR instead regenerates the session id before the token is created, so the token is bound to the fresh id and the rest of the flow (token scope update for password-less backends, remember-me) is unaffected.

How it was verified

  • Reproduced on master before the fix with a minimal IApacheBackend test backend: a pre-authentication session id was re-emitted unchanged after SSO login and was authenticated when replayed.
  • After the fix: the response carries a newly generated session id; replaying the pre-authentication cookie pair is not authenticated (401).
  • The session token is correctly bound to the regenerated id (verified against the authtoken store); the empty($password) token-scope update and remember-me cookie issuance keep working; repeated requests stay logged in.
  • tests/lib/User/ passes (143 tests, 716 assertions). No existing test covers loginWithApache(); happy to add a regression test if desired.

Only master is affected (regression is not in stable33/34/35).

Checklist

  • Code is properly formatted
  • Sign-off message is added to all commits
  • Tests (unit, integration, api and/or acceptance) are included — existing suite passes; see note above
  • Documentation is not required

Disclosure per the AI contribution policy: this change was prepared with AI assistance (Claude Code) and was reviewed, verified and submitted under the direction of the human contributor.

🤖 Generated with Claude Code

Since nextcloud#64582 the IApacheBackend login path calls completeLogin() with
regenerateSessionId: false and binds the freshly created session token
to the pre-authentication session id. This removed the only session id
regeneration on this path, so a session id that existed before
authentication survives into the authenticated session (session
fixation).

Regenerate the session id before creating the session token, so the
token is bound to the fresh id and the login flow (token scope update,
remember-me) keeps working unchanged.

Signed-off-by: Jahn Kohlhas <jaykijay@users.noreply.github.com>
Assisted-by: ClaudeCode:claude-mythos-5
Co-Authored-By: Claude Mythos 5 <noreply@anthropic.com>
@jaykijay
jaykijay requested a review from a team as a code owner October 13, 2026 17:19
@jaykijay
jaykijay requested review from Altahrim, icewind1991, leftybournes and sorbaugh and a balanced review from Copilot and removed request for a team October 13, 2026 17:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The security-critical behavior lacks an automated regression test.

1 open finding
What changed in this PR

Prevents session fixation during Apache/SSO authentication by rotating the session ID before creating its authentication token.

Changes:

  • Regenerates the pre-authentication session ID.
  • Binds the new session token to the rotated ID.
File Description
lib/​private/​legacy/​OC_User.php Rotates the session ID before token creation.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// Regenerate the session id before binding the session token to it, so a
// pre-authentication session id cannot survive into the authenticated
// session (session fixation)
$userSession->getSession()->regenerateId();
@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants