Skip to content

Race condition (TOCTOU) issue fix#2522

Merged
yeshamavani merged 6 commits into
masterfrom
GH-2504
May 19, 2026
Merged

Race condition (TOCTOU) issue fix#2522
yeshamavani merged 6 commits into
masterfrom
GH-2504

Conversation

@vinaygupta-sourcefuse
Copy link
Copy Markdown
Contributor

@vinaygupta-sourcefuse vinaygupta-sourcefuse commented May 5, 2026

Description

Previously, authorization codes could be redeemed multiple times in concurrent requests, allowing attackers to hijack legitimate sessions. The fix ensures auth codes can only be redeemed once, with proper atomic guarantees even under high concurrency.

Fixed race condition vulnerability in authorization code redemption to prevent session hijacking attacks.

Fixes # GH-2504

Screenshot 2026-05-05 at 12 38 15 PM

on second hit of auth/token endpoint it will throw the 'Code Expired Error' [as Expected]

Screenshot 2026-05-05 at 12 39 03 PM

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Intermediate change (work in progress)

Checklist:

  • Performed a self-review of my own code
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Any dependent changes have been merged and published in downstream modules

@vinaygupta-sourcefuse vinaygupta-sourcefuse added the bug Something isn't working label May 5, 2026
@sonarqube-agent
Copy link
Copy Markdown
Contributor

sonarqube-agent AI commented May 5, 2026

SonarQube Remediation Agent

SonarQube found 1 issue in this PR that the agent can fix for you. Est. time saved: ~5 min

1 issue found
  • 🔴 Remove this use of the "void" operator.revoked-token.repository.ts:41
  • Run Remediation Agent
    Select the checkbox above to enable this action.

View Project in SonarCloud

💡 Got issues in your backlog? Let the agent fix them for you.

Comment thread services/authentication-service/src/repositories/index.ts
Comment thread packages/core/locales/en.json
@sonarqubecloud
Copy link
Copy Markdown

SonarQube reviewer guide

Summary: Upgrade TypeDoc and related documentation tools while adding authorization code replay protection.

Review Focus: The core change is adding atomic setIfNotExists method to RevokedTokenRepository for preventing authorization code replay attacks. This is critical security functionality - ensure the atomic Redis operations (SET NX EX) are correctly implemented and properly handle fallback scenarios when Redis doesn't support atomic operations. Also review the race condition acceptance test to verify it adequately validates the protection mechanism.

Start review at: packages/core/src/repositories/revoked-token.repository.ts. This is the foundational security change where the atomic operation for preventing replay attacks is implemented. The method's correctness directly impacts whether concurrent requests attempting to use the same auth code are properly rejected.

💬 Please send your feedback

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
20.5% Duplication on New Code

See analysis details on SonarQube Cloud

@yeshamavani yeshamavani merged commit cedd708 into master May 19, 2026
11 checks passed
@yeshamavani yeshamavani deleted the GH-2504 branch May 19, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants