Skip to content

Lock down /api/nlp: API key auth, rate limit, input validation - #2

Open
KARLalpha4768 wants to merge 1 commit into
mainfrom
fix/api-nlp-lockdown
Open

KARLalpha4768 wants to merge 1 commit into
mainfrom
fix/api-nlp-lockdown

Conversation

@KARLalpha4768

Copy link
Copy Markdown
Owner

Addresses SEC-07.

  • Requires X-API-Key matching NLP_API_KEY (timing-safe compare); 503 if not configured.
  • CORS limited to ALLOWED_ORIGINS instead of *.
  • Per-IP in-memory rate limit, 20 requests/min (best effort per warm serverless instance).
  • Input type/length validation, control characters stripped, input JSON-escaped in the prompt.
  • Gemini key moved from URL query string to x-goog-api-key header; upstream errors not echoed; returned cmd checked against an allow-list.

Note: the browser client must now send X-API-Key; a key shipped in a public page is not secret, so a server-side session or proxy is a follow-up.

Verified (outside the Codex sandbox, Python 3.13.12 on Windows): python -m py_compile on every changed .py and node --check on every changed .js on this branch: 0 failures. pytest -q: 25 passed (baseline before changes: 25 passed). Secret scan: no hardcoded demo API key, Cesium-style JWT token, or postgres credentials remain once all five PRs are merged (each branch alone only removes its own items).

Not verified: docker build (Docker not available on the dev PC), terraform validate/plan, runtime/deployment tests. The existing tests do not exercise most changed code. Changes drafted with headless Codex and reviewed by hand.

One of five PRs splitting the HIGH findings from antigravity-findings-v2: fix/secrets-env, fix/api-nlp-lockdown, fix/docker-build, fix/infra-hardening, fix/correctness-high.

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