Skip to content

fix(security): per-IP lockout and nonce-based CSP - #153

Merged
Sergey-Bar merged 1 commit into
mainfrom
review/security-gaps
Dec 1, 2026
Merged

Sergey-Bar merged 1 commit into
mainfrom
review/security-gaps

Conversation

@Sergey-Bar

Copy link
Copy Markdown
Owner

Summary

Closes the two security gaps that were still actionable in the ASVS/scorecard: per-IP sign-in throttling and a nonce-based script CSP.

Per-IP sign-in lockout

  • New access_ip_attempts table (migration 105).
  • loginUser blocks an IP after 10 failures across any usernames for 15 minutes, alongside the existing per-username limit of 5.
  • Counters reset after an expired block; a successful sign-in clears the username bucket but not the IP bucket, so one valid account cannot reset an attacker's IP budget.
  • The access route passes the client IP from cf-connecting-ip (Cloudflare tunnel) or the first x-forwarded-for hop; direct local requests fall back to local.
  • Tests cover IP parsing, the cross-username block, and that another IP is unaffected.

CSP nonce

  • The proxy now generates a fresh nonce per request and emits script-src 'self' 'nonce-…' 'strict-dynamic'. The static build-time unsafe-inline CSP was removed from next.config.ts.
  • The layout reads x-nonce and applies it to both pre-paint inline scripts.
  • The statically prerendered /_global-error page keeps the legacy inline policy so its bootstrap scripts continue to work; all normal pages are dynamic and use the nonce.
  • Tests assert the nonce policy, the absence of unsafe-inline for scripts, the proxy response header, and the global-error exception.

Docs

  • Removed the per-IP and CSP-nonce rows from docs/qa/asvs-l2.md Known gaps.
  • Updated the scorecard: security remaining is now keychain/SQLCipher only, E2E CI evidence is recorded, and coverage numbers refreshed.

Verification

  • npm test: 3370 passed (1 skipped)
  • coverage 85.89 / 75.60 / 87.21 / 88.37; diff coverage 100% (proxy, user-access); components floor passes
  • next build passed; e2e:p0 28/28; e2e:rest 66/66
  • lint, typecheck, Prettier, Knip, OpenAPI, test-focus, dependency security gate passed

Still not closable here

  • OS keychain (DPAPI/Keychain/libsecret) and SQLCipher need platform/native packaging work.
  • ZAP active scan needs a tested ruleset/threshold; the daily baseline + API scan remain in place.
  • External penetration test and the 90/85 coverage / 80 mutation targets are measurement/infra work, not code gaps.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dcbe9b04-0b72-48e6-b1db-3517fcfea142
Commits

Reviewing files that changed from the base of the PR and between 0cde638 and c2014d3.

Files selected for processing: 13

  • docs/qa/asvs-l2.md
  • docs/qa/scorecard.md
  • next.config.ts
  • src/app/api/access/route.ts
  • src/app/layout.tsx
  • src/lib/csp.ts
  • src/proxy.ts
  • src/server/db/migrations/105_access_ip_attempts.sql
  • src/server/lib/user-access.ts
  • tests/proxy.test.ts
  • tests/security-headers.test.ts
  • tests/security/headers.test.ts
  • tests/security/ratelimit.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Sergey-Bar
Sergey-Bar merged commit 8a409bd into main Dec 1, 2026
13 checks passed
@Sergey-Bar
Sergey-Bar deleted the review/security-gaps branch December 1, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant