#19755: fix(security): OC-32 enforce content size limit in agents.files.set to prevent disk exhaustion DoS
app: web-ui
gateway
size: XS
trusted-contributor
Cluster:
Security Enhancements for TTS
## Summary
- Added maxLength: 10485760 to TypeBox schema content field in AgentsFilesSetParamsSchema
- Added explicit Buffer.byteLength guard in agents.files.set handler before fs.writeFile
## Security Impact
**OC-32 medium (CWE-400, CVSS 6.5)** — Attack vectors remediated:
1. Authenticated attacker sends arbitrarily large string via agents.files.set WS method causing disk exhaustion and gateway DoS
## Changes
| File | Change |
|------|--------|
| `src/gateway/protocol/schema/agents-models-skills.ts` | Add maxLength: 10485760 to Type.String() for content field |
| `src/gateway/server-methods/agents.ts` | Add 10MB byte-length check before fs.writeFile in handler |
## Test plan
- [x] Schema rejects strings > 10MB at protocol layer
- [x] Handler returns INVALID_REQUEST error if content byte length > 10MB
- [x] Normal writes under 10MB proceed as before
---
*Created by [Aether AI Agent](https://tryaether.ai) — AI security research and remediation agent.*
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR adds a 10MB content size limit to the `agents.files.set` endpoint to prevent disk exhaustion DoS (OC-32, CWE-400). The fix is applied at two layers:
- **Schema layer**: `maxLength: 10485760` on the `content` field in `AgentsFilesSetParamsSchema` provides character-count validation via AJV
- **Handler layer**: `Buffer.byteLength` check before `fs.writeFile` enforces the actual byte-size limit and returns an `INVALID_REQUEST` error if exceeded
The handler-level byte check is the authoritative enforcement. The schema-level character check is a reasonable first-pass filter but does not precisely map to bytes for multi-byte UTF-8 content. The changes are minimal, focused, and follow existing error handling patterns in the codebase.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it adds a defensive size limit with no impact on existing behavior for content under 10MB.
- The changes are minimal and well-scoped. The handler-level byte check correctly prevents disk exhaustion. The only minor observation is the schema maxLength counting characters rather than bytes, which is a cosmetic mismatch, not a security gap. No existing tests were broken, and the error handling follows established patterns.
- No files require special attention.
<sub>Last reviewed commit: ed6945f</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#19763: fix(security): OC-53 enforce prompt size limit to prevent DoS — Aet...
by aether-ai-agent · 2026-02-18
76.5%
#23420: Gateway: tighten WS connect schema bounds and validation
by bmendonca3 · 2026-02-22
73.8%
#19764: fix(security): OC-65 fix compaction counter reset to prevent contex...
by aether-ai-agent · 2026-02-18
73.2%
#9598: fix(agents): check base64 string length against 5MB API limit
by BlockBB · 2026-02-05
72.3%
#20381: feat(gateway): make chat history byte limit configurable via `gatew...
by mgratch · 2026-02-18
71.7%
#21136: fix(security): harden agent autonomy controls
by novalis133 · 2026-02-19
71.1%
#23803: Fix tool metadata truncation
by kamal-ayman · 2026-02-22
71.1%
#6805: fix: increase WebSocket MAX_PAYLOAD_BYTES to 6MB for attachments
by cortexuvula · 2026-02-02
70.5%
#18924: fix(security): tighten permissions on cron/, browser/, settings/ dirs…
by rexlunae · 2026-02-17
70.2%
#5649: fix(security): harden file permissions and header merging
by sfo2001 · 2026-01-31
69.9%