mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 12:52:11 +03:00
The prompt-injection guard joined every message/system string into one buffer and ran several regexes over the whole thing on every chat request, with no size cap. At high concurrency with large bodies (300 KB of pasted code / RAG context) that is O(body) CPU scanning on the hot path — a self-inflicted latency/GC source under load. Bound both detection call sites — detectInjection() in inputSanitizer.ts and the custom-pattern scan in promptInjection.ts — to the first 16 KB via a named MAX_INJECTION_SCAN_BYTES constant, slicing the joined text before the regex loop. Injection directives sit near the top of a prompt, so the generous cap preserves real detection while scanning only a bounded prefix. No call site removed and opt-out behavior unchanged; this only bounds the scan length. The existing 10 MB body-size cap that protects ingestion is separate and untouched. TDD: tests/unit/injection-guard-scan-bound-3932.test.ts proves a directive at the top of a >16 KB body is still detected (case 1) while the same marker placed beyond the 16 KB cap is no longer scanned (case 2, RED before the fix), at both call sites. Refs #3932