Repository navigation
feat(security): security headers, session management, API tokens, audit logging - #1033
Merged
Merged
Conversation
… audit logging - Stellar-split#925: Add X-XSS-Protection: 1; mode=block header to next.config.js, completing the full set of required security headers (X-Frame-Options, X-Content-Type-Options, X-XSS-Protection, HSTS, Referrer-Policy, Permissions-Policy) - Stellar-split#923: Add server-side secure session management (src/lib/sessionManager.ts) - Signed session tokens (HMAC-SHA256) to prevent tampering - Configurable inactivity timeout (default 30 min) - Session regeneration on login to prevent session fixation - Proper logout via cookie clear + server-side invalidation - Concurrent session limit per user with oldest-first eviction - Server-side activity tracking (touchSession) - Secure httpOnly, SameSite=Strict, Secure cookie configuration - Stellar-split#924: Add OAuth 2.0-style API token system (src/lib/apiTokens.ts) - Short-lived JWT-style access tokens (15 min, HMAC-SHA256 signed) - Long-lived opaque refresh tokens (30 days) with rotation - Replay detection: re-use of rotated token revokes entire token family - Scope hierarchy: read ⊂ write ⊂ admin - Bearer token extraction + scope enforcement helper - Stellar-split#926: Add security audit logging (src/lib/securityAuditLog.ts) - 26 typed security event types (auth, session, API, admin, data) - Severity levels: info | warn | critical with sensible defaults - Tamper-evident hash chain (SHA-256, each entry hashes the previous) - Immutable log entries (Object.freeze) - Configurable retention policy (default 90 days, AUDIT_LOG_RETENTION_DAYS) - Query/filter by event type, severity, actor, time range, free text - CSV and JSON export - Log integrity verification - Fix pre-existing missing file: lib/reliability/retryMetrics.ts (required by vitest.setup.ts; its absence was causing all tests to fail to load) Tests: 48 new tests in src/__tests__/security-features.test.ts, all passing
|
@mirabuidl-code Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@mirabuidl-code is attempting to deploy a commit to the kingsman-99's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
Implements four security features in a single PR.
#925 — Security headers
Adds the missing
X-XSS-Protection: 1; mode=blockheader tonext.config.js, completing the required set:X-Frame-OptionsDENYX-Content-Type-OptionsnosniffX-XSS-Protection1; mode=block(new)Strict-Transport-Securitymax-age=63072000; includeSubDomains; preloadReferrer-Policystrict-origin-when-cross-originPermissions-Policycamera=(), microphone=(), geolocation=(), payment=(self)#923 — Secure session management
New
src/lib/sessionManager.ts:SESSION_TIMEOUT_SECONDS(default 30 min);getSession()auto-expires stale sessionsregenerateSession()issues a new ID after login/MFA to prevent session fixation attacksdestroySession()invalidates the server record;clearSessionCookie()removes the client cookieMAX_CONCURRENT_SESSIONS = 5; oldest session evicted when exceededtouchSession()updates last-seen timestamp;listUserSessions()shows all active sessionshttpOnly,SameSite=Strict,Secure(on HTTPS)#924 — API authentication (OAuth 2.0-style)
New
src/lib/apiTokens.ts:jti,sub,scopes,iat,expread | write | adminwith hierarchy (admin ⊇ write ⊇ read)revokeAccessToken()/revokeRefreshToken()/revokeAllUserTokens()checkApiAuth(authHeader, requiredScope)helper for route handlers#926 — Security audit logging
New
src/lib/securityAuditLog.ts:auth.*,session.*,api.*,admin.*,data.*info | warn | criticalwith sensible per-event defaultsverifyLogIntegrity()detects any modificationObject.freeze()AUDIT_LOG_RETENTION_DAYS(default 90 days);purgeExpiredLogs()trims old entriessecurityLogToCsv()andsecurityLogToJson()Tests
48 new tests in
src/__tests__/security-features.test.ts— all passing.Pre-existing test baseline: 38 failed / 181 passed → After: 37 failed / 182 passed (improved by fixing a pre-existing missing file
lib/reliability/retryMetrics.tsthat was causing the setup to fail).Closes #923
Closes #924
Closes #925
Closes #926