Repository navigation
feat(server): add startup security checks for secrets and origins - #317
Conversation
Adds checkSecuritySettings() in packages/server/src/security/startup-checks.ts and tests. Reports errors/warnings for: - session secrets < 32 bytes (UTF-8) - secret matches NEXT_PUBLIC_, VITE_, PUBLIC_, NUXT_PUBLIC_, EXPO_PUBLIC_, REACT_APP_ env vars - allowed origin not http(s):// or * - origin with path/query/trailing slash - * combined with other origins - duplicate secrets (warn) - http:// origin not localhost/127.0.0.1 (warn) Not exported from @chatcops/server yet. Closes codercops#231
anurag629
left a comment
There was a problem hiding this comment.
Thanks @varun-pahuja, this does everything #231 lists. There's one test per rule, a clean config returns [], and a test shows the secret never shows up in a message. Bytes are counted in UTF-8, env falls back safely where there's no process, nothing is exported yet, and the changeset is empty. I also tried a few origins the issue didn't name: https://*.acme.com and https://acme.com:8443 pass as they should. Locally the server suite passes (332 tests, 96% lines), and lint is unchanged from dev.
A small note on the PR description: it lists * together with other origins as an error, but the code reports it as a warning, which is what the issue asked for. The code is right.
Two things I'll handle when I wire this into the startup log (T4), so nothing to change here:
- The origin messages say "Allowed origin 2" rather than showing the origin. Origins aren't secret, so I'll put the value in the message so it's easier to act on.
https://acme.com#xpasses. A fragment is never part of an origin either, so I'll count it like a path.
What does this change?
Adds startup security checks for session secrets and allowed origins as a new module `packages/server/src/security/startup-checks.ts`. Reports errors for: secrets < 32 bytes (UTF-8), secrets that match public env vars (NEXT_PUBLIC_, VITE_, PUBLIC_, NUXT_PUBLIC_, EXPO_PUBLIC_, REACT_APP_), origins not starting with http(s)://, origins with path/query/trailing slash, and `*` combined with other origins. Warns for: duplicate secrets, http:// origins not localhost/127.0.0.1. Not exported from `@chatcops/server` yet (will be called by handler in follow-up).
Closes #231
How I tested this
AI assistance
Claude Code — wrote the implementation, tests, and changeset. I reviewed and ran all gates.
Checklist