CWE-400
- Location
src/server.ts:62- Finding
Unbounded Sender State and Burst Processing Can Exhaust Gateway Resources ## Remediation Suggestions 1. **Bound sender storage.** Enforce a configurable maximum number of tracked senders and evict inactive entries using TTL and LRU policies. Run cleanup independently of future messages from the same sender. 2. **Replace timestamp-array scans.** Use a fixed-size time-bucket counter or bounded queue. Limit both memory consumption and processing cost per inbound message. 3. **Enforce ingress limits.** Apply per-sender and global rate limits before state updates and logging. Use gateway-level admission controls to address distributed traffic across multiple identities. 4. **Aggregate burst logging.** Record the transition into a burst condition and periodic summaries instead of writing a record for every excess message. 5. **Bound logging overhead.** Use asynchronous buffered writes with a capped queue and an explicit overload policy. Ensure excessive logging cannot block the gateway event loop. 6. **Add adversarial-load tests.** Test concentrated traffic within a 60-second window, many distinct senders, idle-state expiration, and sustained burst logging. Verify bounded state size, queue depth, and processing latency.
- Content
View full analysis
Vulnerability Details
File Location:
src/server.ts:62–68, 141–148; inbound trigger insrc/index.ts:142–164. The corresponding behavior is also present indist/server.jsanddist/index.js.Vulnerability Type: CWE-400 — Uncontrolled Resource Consumption
Risk Level: Medium
Complete Code Snippet
The inbound hook processes every admitted message and logs repeated burst events:
ts onMsg("message_received", (event: unknown) => { if (!cfg.enabled || !server) return; const e = event as { content?: string; senderId?: string; senderIsOwner?: boolean; sessionKey?: string; }; if (!e || typeof e.content !== "string") return; const senderId = String(e.senderId ?? "unknown"); const recent = server.recentCount(senderId); if (recent > 12 && !(e.senderIsOwner === true)) { server.recordVerdict(senderId, "flag", ["spam.burst"]); (api.logger.warn ?? api.logger.info).call( api.logger, `jerith-guard: sender ${server.senderTag(senderId)} burst=${recent}/60s — flagged` ); } return undefined; });The counter filters and grows an array on every message:
ts recentCount(senderId: string, now = Date.now()): number { const s = this.get(senderId, now); s.messageTimestamps = s.messageTimestamps.filter((t) => now - t < this.windowMs); s.messageTimestamps.push(now); s.lastSeenAt = now; return s.messageTimestamps.length; }Sender records are created without a capacity limit or eviction:
ts private get(senderId: string, now = Date.now()): SenderState { let s = this.state.get(senderId); if (!s) { s = { messageTimestamps: [], verdicts: [], threatScore: 0, firstSeenAt: now, lastSeenAt: now, lastVerdictAt: now }; this.state.set(senderId, s); } return s; }Technical Analysis
Two resource-management weaknesses are reachable through the inbound-message hook:
- Unbounded sender retention. Each previously unseen sender creates a map entry. No idle expiration or ...[truncated 2713 chars]
