Skip to content

Security & cost hardening: rate-limit + validate AI/OSM endpoints#3

Open
joaquinOEF wants to merge 1 commit into
mainfrom
feat/security-cost-hardening
Open

Security & cost hardening: rate-limit + validate AI/OSM endpoints#3
joaquinOEF wants to merge 1 commit into
mainfrom
feat/security-cost-hardening

Conversation

@joaquinOEF

Copy link
Copy Markdown
Owner

The /api/chat/* and /api/osm/* endpoints called OpenAI / Overpass with no rate limit, no input validation, no body-size cap, and no timeout — an attacker could run up the OpenAI bill, use the server as a free OpenAI/Overpass proxy, or OOM it with a huge payload.

  • Rate limit 40/min/IP on /api/chat + /api/osm (express-rate-limit)
  • Validation: zod on /api/chat/query (string ≤500 chars + optional bbox tuple); cap index-assets ≤5000, index-geojson features ≤20000, overpass query ≤10k chars
  • Payload limits: express.json/urlencoded capped at 1 MB
  • OpenAI timeout 15s + 2 retries (a hung call can no longer block the server)
  • Health check no longer leaks OPENAI_API_KEY presence
  • .gitignore now ignores .env*

Low-risk + additive; npm run build passes. First of four small audit PRs (A security → B perf → C cleanup → D UX).

🤖 Generated with Claude Code

… OpenAI timeout

The /api/chat/* and /api/osm/* endpoints called OpenAI / Overpass with no auth, no rate
limit, no input validation, and no body-size cap — anyone could run up the OpenAI bill, use
us as a free proxy, or OOM the server with a huge payload.

- express-rate-limit (40/min/IP) on /api/chat and /api/osm
- zod-validate /api/chat/query (string ≤500 chars + optional bbox tuple); cap index-assets
  (≤5000), index-geojson features (≤20000), overpass query length (≤10k)
- express.json/urlencoded limit 1mb
- OpenAI client timeout 15s + maxRetries 2 (a hung call can't block the server)
- health check no longer leaks OPENAI_API_KEY presence
- .gitignore .env*

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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