security: add helmet, rate limiting, strict CORS, input sanitization.

- Add helmet for secure HTTP response headers.
- Add express-rate-limit: 60 req/min general, 20 req/min on LLM endpoints.
- Restrict CORS to localhost origins in dev, CORS_ORIGIN env var in prod.
- Cap request body at 16kb.
- Add sanitizeText() to strip control chars on all string inputs.
- Add isValidStandardId() regex guard on :id param and standard_id fields.
- All route handlers use sanitized values; no raw req.body/req.query access.
This commit is contained in:
K
2026-05-02 23:59:33 +05:30
parent 92cc8274df
commit 0d8b2cdb3f
3 changed files with 141 additions and 40 deletions
+5 -3
View File
@@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"start": "node start.js",
"dev": "node start.js",
"test": "echo \"Error: no test specified\" && exit 1"
"dev": "node start.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
@@ -15,6 +15,8 @@
"dependencies": {
"cors": "^2.8.6",
"dotenv": "^17.4.2",
"express": "^5.2.1"
"express": "^5.2.1",
"express-rate-limit": "^8.4.1",
"helmet": "^8.1.0"
}
}