Skip to content

security: clamp list_pages and get_ingest_log limits#109

Open
garagon wants to merge 1 commit intogarrytan:masterfrom
garagon:security/r5-f007-uncapped-limits
Open

security: clamp list_pages and get_ingest_log limits#109
garagon wants to merge 1 commit intogarrytan:masterfrom
garagon:security/r5-f007-uncapped-limits

Conversation

@garagon
Copy link
Copy Markdown
Contributor

@garagon garagon commented Apr 13, 2026

Summary

Several gbrain MCP operations accept a limit parameter that controls how many
results to return. The search and query operations were already capped at 100 via
clampSearchLimit (fixed in v0.9.1). Two other operations were not:

  • list_pages: (p.limit as number) || 50 — no cap
  • get_ingest_log: (p.limit as number) || 20 — no cap

The problem: an MCP caller can pass {limit: 10000000} and force the engine to
return an unbounded result set, consuming memory on the server.

What the fix does

Both operations now use clampSearchLimit(p.limit, defaultValue) — the same function
that already caps search and query. The ceiling is MAX_SEARCH_LIMIT = 100.
Normal usage (limit under 100) is unaffected.

Changes

src/core/operations.ts

  • Import clampSearchLimit from engine.ts
  • list_pages handler: clampSearchLimit(p.limit, 50)
  • get_ingest_log handler: clampSearchLimit(p.limit, 20)

Validation

  • bun test test/parity.test.ts — 10 pass (operation contract intact)
  • bun test test/search-limit.test.ts — 11 pass (clamp logic verified)
  • Runtime: clampSearchLimit(10000000, 50) → 100, clampSearchLimit(undefined, 50) → 50

list_pages and get_ingest_log pass caller-supplied limit values
directly to the engine without capping. An MCP caller with
{limit: 10000000} forces unbounded result sets. Apply the same
clampSearchLimit (max 100) already used by search/query operations.
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.

1 participant