fix(security): Implement X-Force Red session token security fixes (ICACF-22)#4406
Draft
MohanLaksh wants to merge 3 commits intomainfrom
Draft
fix(security): Implement X-Force Red session token security fixes (ICACF-22)#4406MohanLaksh wants to merge 3 commits intomainfrom
MohanLaksh wants to merge 3 commits intomainfrom
Conversation
…ACF-22) Addresses X-Force Red penetration testing findings for session token vulnerabilities. Implements comprehensive security improvements to prevent token replay attacks after logout. Changes: - Reduce session token lifetime from 30 days to 15 minutes (configurable) - Implement server-side token revocation with TokenRevocation table - Add POST /auth/logout endpoint with immediate token blocklist - Update admin UI logout to revoke tokens server-side - Add security validation warnings for excessive token expiry values Security improvements: - Token replay attacks prevented via server-side revocation - Revocation persists in database (source of truth) - Redis-cached revocation for performance - Complete audit trail (JTI, revoked_by, revoked_at, reason) - Idempotent logout operations (DoS prevention) Test coverage: - 10 unit tests (token lifetime, revocation, logout endpoints) - 15 security tests (threat modeling, attack scenarios) - 7 integration tests (E2E login → logout → revocation flow) Breaking changes: - Session token expiry reduced from 10080 minutes (7 days) to 15 minutes - Automation scripts using session tokens must migrate to API tokens Migration guide included in CHANGELOG.md Closes #4324 Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com>
Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com>
9bd4650 to
851cf29
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Statement
X-Force Red penetration testing identified critical session token vulnerabilities (ICACF-22):
Security Impact: An attacker who steals a session token (via XSS, network sniffing, etc.) can continue using it even after the user logs out, potentially for up to 7 days.
Solution Overview
This PR implements comprehensive server-side token revocation and reduces session token lifetime per X-Force Red recommendations:
1. Reduced Token Lifetime (15 minutes)
TOKEN_EXPIRYfrom 10080 minutes (7 days) to 15 minutes for session tokens2. Server-Side Token Revocation
POST /auth/logoutendpoint that revokes session tokens server-sideTokenRevocationdatabase table tracks revoked tokens with audit trail (jti, revoked_by, revoked_at, reason)3. Admin UI Logout Enhancement
Technical Implementation
Files Modified
Core Implementation:
mcpgateway/config.py- Token expiry configuration and security warningsmcpgateway/routers/auth.py- New logout endpoint with revocation logicmcpgateway/admin.py- Admin UI logout with server-side revocation.env.example- Updated TOKEN_EXPIRY documentation with migration guidanceConfiguration:
pyproject.toml- Addedsecuritypytest marker registrationCHANGELOG.md- Breaking changes documentation with migration examplesDatabase:
TokenRevocationtable (jti, revoked_by, revoked_at, reason)Test Coverage (32 Tests Total)
Unit Tests (10) -
tests/unit/mcpgateway/test_auth.pySecurity Tests (15) -
tests/security/test_session_token_security.pyIntegration Tests (7) -
tests/integration/test_auth_logout_flow.pyTest Fixes (2)
tests/unit/mcpgateway/test_config.py- Updated warning assertiontests/unit/mcpgateway/test_admin_module.py- Fixed logout test mocksSecurity Properties Validated
✅ Revoked tokens rejected immediately (no replay attacks)
✅ Token expiry ≤20 minutes (X-Force Red guideline)
✅ Logout only accepts session tokens (not API tokens)
✅ Idempotent logout (DoS prevention)
✅ Complete audit trail (jti, revoked_by, revoked_at, reason)
✅ Database persistence (cache failures don't bypass revocation)
✅ Unauthenticated logout rejected (401 Unauthorized)
Breaking Changes
Session Token Lifetime Reduced: 7 days → 15 minutes
Migration Required for automation/long-running tasks:
Before (session tokens, now invalid after 15 min):
After (use API tokens for automation):
See
CHANGELOG.mdfor complete migration guide.Verification
Quality Checks (All Passed)
Test Coverage
Manual Testing
Security Audit Compliance
X-Force Red Findings Addressed:
Threat Model Coverage:
Deployment Notes
Configuration Changes Required
Database Migration
No new migrations required - reuses existing
TokenRevocationtable from schema.Backward Compatibility
Rollback Plan
References
🚀 Ready for Review