Track 10 · Lesson 1 of 4Capstone
Audit your own project
Lesson 1 of 4· 20 min
Time to point everything at real code: yours. Answer twenty-four questions about how your project handles sessions, cookies, refresh and attacks, find where each piece lives, then work through the review findings that apply.
Audit your auth
Yes, no or not sure: saved in this browser
Storage
Long-lived credentials (refresh tokens, session IDs) are never readable by page JavaScript.
No tokens are kept in localStorage or sessionStorage.
Access tokens expire within an hour (or sessions have an idle timeout).
Secrets never use a public env prefix (NEXT_PUBLIC_, VITE_, REACT_APP_, PUBLIC_).
Cookies
Auth cookies are HttpOnly, Secure, and SameSite=Lax or Strict.
Auth cookies are host-only, with the narrowest Path that works.
Cookies that carry credentials are encrypted, or hold only a random ID.
Setting and clearing a cookie share the same options.
Sessions and refresh
Refresh tokens rotate, and retired ones are rejected (allowing a short grace window at most).
Only a definitive 'session dead' answer logs users out; 429, 5xx and network errors keep the session.
Concurrent refreshes in one tab and across tabs are coordinated.
A 401 triggers at most one refresh-and-retry per request.
Logout revokes the session or refresh token on the server.
Logout clears all per-user client state: caches, storage, sockets, analytics identity.
Attacks
Cookie-authenticated, state-changing routes are protected against CSRF (SameSite plus an Origin check or CSRF token).
User HTML and markdown are sanitized; no raw HTML sinks.
A Content-Security-Policy is enforced, ideally without 'unsafe-inline' in script-src.
Login has lockout or backoff, rate limiting, and a bot check.
Post-login redirect targets are validated (no open redirect).
Login, reset and resend responses don't reveal whether an account exists.
Every API request is authorized on the server; UI guards are only UX.
Operations
Signing and cookie keys can be rotated without signing everyone out.
Refresh failures, forced logouts and 401 spikes are monitored.
Rate limiters see the real client IP behind proxies and CDNs.
Answer from the code, not from memory#
“I think we set HttpOnly” isn’t a yes. Open the file, find the line, then answer. Anything you can’t confirm in a few minutes is “not sure”, which is a finding in its own right: nobody on the team knows.
Where to look#
Every codebase hides these in different places, but the names are predictable. Each row has a search you can paste into a terminal at the root of your project (it uses ripgrep, rg).
Find it in your codebase
Copy a search, run it, read the hits
Where login issues the session or tokens
loginsignInauthenticatejwt.signSignInAsynccreate_sessionUsually in: auth routes, controllers, route handlers, services/auth
rg -n -i "login|signIn|authenticate|jwt\.sign|SignInAsync|create_session"Where tokens are stored in the browser
localStorage.setItemsessionStoragedocument.cookieaccessTokenUsually in: auth context/store, API client, utils/auth
rg -n -i "localStorage\.setItem|sessionStorage|document\.cookie|accessToken"Cookie flags and lifetime
Set-Cookieres.cookie(cookies().set(SESSION_COOKIECookieOptionshttpOnlyUsually in: server config, session middleware, cookie helpers
rg -n -i "Set-Cookie|res\.cookie\(|cookies\(\)\.set\(|SESSION_COOKIE|CookieOptions|httpOnly"Refresh logic
refreshinterceptorsonResponseError401retryUsually in: API client, fetch wrapper, HTTP interceptor
rg -n -i "refresh|interceptors|onResponseError|401|retry"Logout and revocation
logoutsignOutrevokedestroy_sessionUsually in: auth routes, auth context, user menu
rg -n -i "logout|signOut|revoke|destroy_session"Who can do what (authorization)
authorizecan(policyguard[Authorize]@PreAuthorizelogin_requiredbefore_actionUsually in: API middleware, policies, controllers
rg -n -i "authorize|can\(|policy|guard|\[Authorize\]|@PreAuthorize|login_required|before_action"Route protection in the UI
middlewareProtectedRouteRequireAuthbeforeEachredirect('/login')Usually in: router config, layouts, middleware file
rg -n -i "middleware|ProtectedRoute|RequireAuth|beforeEach|redirect\('/login'\)"CSP and security headers
Content-Security-Policyhelmetheaders()SecurityMiddlewareUsually in: framework config, reverse proxy (nginx, CDN)
rg -n -i "Content-Security-Policy|helmet|headers\(\)|SecurityMiddleware"Rate limiting and lockout
rate-limitthrottleLockoutMaxFailedAccessAttempts429Usually in: API gateway, middleware, identity config
rg -n -i "rate-limit|throttle|Lockout|MaxFailedAccessAttempts|429"Secrets and keys
SECRETKEYprocess.env.envNEXT_PUBLIC_VITE_Usually in: .env files, deployment settings, secret manager
rg -n -i "SECRET|KEY|process\.env|\.env|NEXT_PUBLIC_|VITE_"Real-time auth
WebSocketsocket.io authaccessTokenFactoryaccess_tokenUsually in: socket/hub service
rg -n -i "WebSocket|socket\.io auth|accessTokenFactory|access_token"
Every finding, one at a time#
The review cards from the last two tracks, all in one place. Start with Critical, tick what you’ve checked, and file a ticket for anything you find.
Review findings
Filter by severity
In a code review
CriticalFrontend / BackendKnown-vulnerable dependency
Fix: Bump to the fixed version; force transitive ones with an override or resolution; rerun the audit until no High remains; automate it in CI.
0 of 3 checked
In a code review
CriticalDevOpsSecret committed to git or baked into an image
Fix: Rotate and revoke first, review provider access logs for the exposure window, delete old images and stale CI secrets. Purging history is optional once the key is dead.
0 of 3 checked
In a code review
CriticalBackendSQL or command injection
Fix: Use parameterised queries and argument arrays everywhere; validate input types; run the database user with least privilege.
0 of 3 checked