fix(security): harden session, CORS, rate limiting, and cache isolation - #31
Open
lupita-hom wants to merge 1 commit into
Open
fix(security): harden session, CORS, rate limiting, and cache isolation#31lupita-hom wants to merge 1 commit into
lupita-hom wants to merge 1 commit into
Conversation
npm audit is clean on both client and server (0 vulnerabilities), but a code review of the server surfaced several exploitable weaknesses: - Session secret: production no longer falls back to a hardcoded 'dev-secret-change-in-production'; boot fails unless SESSION_SECRET is >= 32 chars. A known secret allows forging session cookies. - Session fixation: regenerate the session id after OAuth token exchange and clear the cookie on logout. - OAuth CSRF: constant-time state comparison, reject missing/non-string state, and make state single-use to block callback replay. - CORS: replace the single-origin value with a validated ALLOWED_ORIGINS allowlist and restrict methods. - Rate limiting: add express-rate-limit (600/15m API, 30/15m auth) to protect the upstream GitHub token and slow OAuth brute force. - CSP: restore an explicit policy (no upgrade-insecure-requests) plus no-referrer and same-origin CORP instead of disabling CSP outright. - Body size: bound JSON/urlencoded bodies to 100kb. - Cache poisoning / cross-user leak: derive a SHA-256 per-user cache namespace instead of using an 8-char access-token substring, and apply it to every repo/org cache key. Also cap cache size at 5000 keys. - Injection: allowlist the PR 'state' value interpolated into the upstream GraphQL query. - Input bounds: clamp all user-controlled pagination and maxCommits / tzOffset parameters. - Cookie: opt-in Secure flag via COOKIE_SECURE, non-default cookie name. - Deps: override qs to >=6.16.0; document ALLOWED_ORIGINS and COOKIE_SECURE in .env.example. Validated with tsc --noEmit and full client + server production builds.
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.
Automated security scan — 2026-09-07
Dependency audit
npm auditis clean on both workspaces (0 vulnerabilities, client and server). Nonpm audit fixchanges were needed.Code review findings (all fixed here)
dev-secret-change-in-production— forgeable session cookiesSESSION_SECRET>= 32 chars in productionreq.session.regenerate()after token exchange; cookie cleared on logoutstatecompared with!==, not single-use, missing-value not rejectedALLOWED_ORIGINSallowlist, methods restricted to GET/POST/OPTIONSexpress-rate-limit: 600/15m API, 30/15m authupgrade-insecure-requests, plusno-referrer+ same-origin CORPstatequery param interpolated into upstream GraphQLpage,per_page,maxCommits,tzOffsetunboundedsecure: falsehardcoded, defaultconnect.sidnameCOOKIE_SECURE, renamed togne.sidqstransitive>=6.16.0trust proxyset to1so rate limiting and secure cookies see the real client IP behind one reverse proxy.Validation
tsc --noEmit— cleanserverproduction build — passclientproduction build — passnpm auditafter changes — 0 vulnerabilitiesOperator note
Two new optional env vars are documented in
.env.example:ALLOWED_ORIGINSandCOOKIE_SECURE.SESSION_SECRETis now mandatory in production — deployments without it will fail to start (intentionally).🤖 Automated scheduled security scan