Skip to content

sec: RASP middleware — runtime attack detection + anomaly scoring#125

Merged
Pyronewbic merged 2 commits into
mainfrom
dev
May 20, 2026
Merged

sec: RASP middleware — runtime attack detection + anomaly scoring#125
Pyronewbic merged 2 commits into
mainfrom
dev

Conversation

@Pyronewbic
Copy link
Copy Markdown
Owner

Summary

  • Add lib/security/rasp.js — runtime request inspection middleware
  • Detects: SQLi, XSS, command injection, path traversal, NoSQL injection, prototype pollution
  • Per-IP anomaly scoring with 5-min half-life decay and bot fingerprinting
  • Monitor mode by default (RASP_MODE=block to enforce)
  • Events logged to security-events Firestore collection
  • GET /api/security/events (owner-only) for event dashboard
  • 43 unit tests covering all detection categories + false positive safety for card names

Test plan

  • Unit tests pass (43 new RASP tests)
  • ZAP DAST still passes (ZAP UA gets lower bot score, not blocked)
  • Normal card searches not flagged as false positives
  • Security events appear in Firestore after attack payloads

lib/security/rasp.js: inspect all inputs (query, body, path, headers)
for SQLi, XSS, command injection, path traversal, NoSQL injection,
prototype pollution. Per-IP anomaly scoring with 5-min half-life decay,
bot fingerprinting (scanner UA detection, ZAP allowlisting). Events
logged to security-events Firestore collection. Monitor mode by default
(RASP_MODE=block to enforce). GET /api/security/events (owner-only).
43 unit tests covering all detection categories + false positive safety.
Comment thread lib/security/rasp.js

if (!ua) flags.push("missing-ua");
else if (SCANNER_PATTERNS.test(ua)) flags.push("scanner-ua");
else if (ZAP_PATTERN.test(ua)) flags.push("zap-ua");
Object literal { __proto__: ... } sets prototype, doesn't create a key.
Use Object.create(null) to test actual key detection. ZAP fingerprint
test needed accept header to avoid extra missing-accept flag inflating
bot score from 5 to 35.
@Pyronewbic Pyronewbic merged commit fc25aac into main May 20, 2026
16 of 17 checks passed
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.

2 participants