fix: add API body size limits and memory content validation#123
Merged
jamiepine merged 2 commits intospacedriveapp:mainfrom Feb 22, 2026
Merged
Conversation
Add a 10MB DefaultBodyLimit to the API router to prevent unbounded request bodies (especially multipart file uploads) from exhausting server memory. Add input validation to the memory_save tool: - Content size capped at 50KB to prevent database/embedding bloat - Empty content rejected - Importance score validated to 0.0-1.0 range at runtime Files changed: - api/server.rs: add DefaultBodyLimit::max(10MB) layer - tools/memory_save.rs: add MAX_MEMORY_CONTENT_BYTES constant, content size check, empty check, importance range validation
jamiepine
previously approved these changes
Feb 22, 2026
jamiepine
approved these changes
Feb 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add missing input validation to prevent resource exhaustion via unbounded request bodies and oversized memory content.
Changes
src/api/server.rs— API body size limit (M9)Added
DefaultBodyLimit::max(10 * 1024 * 1024)(10MB) as a layer on the API router.Before: No body size limit — the multipart upload endpoint (
/api/agents/ingest/upload) and other POST endpoints could accept arbitrarily large request bodies, risking memory exhaustion.After: All API endpoints are capped at 10MB. This covers:
Jsonextractor — previously had axum's 2MB default, now explicitly set)Multipartextractor — previously unlimited)10MB is generous enough for file ingestion while preventing abuse.
src/tools/memory_save.rs— Memory content validation (M5)Added three validation checks to the
memory_savetool:Before: The LLM could save arbitrarily large content as a memory — a single 10MB memory would generate a massive embedding, bloat the vector index, and pollute any recall that retrieved it.
After: Content capped at 50KB (consistent with the existing
MAX_TOOL_OUTPUT_BYTESlimit used for tool output truncation). Importance validated at runtime, not just in the JSON schema.What's NOT in this PR
These items were investigated and found to already be handled or to require maintainer design input:
check_worker_limit(), configurable via ArcSwapSpacebotHook.on_tool_result()scans ALL tool outputs (including MCP) for leaked secretsapi_auth_middlewareTesting
rust-analyzerdiagnostics with zero errors