Skip to content

feat(web): enforce response-size limits on public analytics endpoints (#417) - #484

Open
Emmycivity wants to merge 1 commit into
enliven17:mainfrom
Emmycivity:feat/enforce-response-size-limits-analytics
Open

feat(web): enforce response-size limits on public analytics endpoints (#417)#484
Emmycivity wants to merge 1 commit into
enliven17:mainfrom
Emmycivity:feat/enforce-response-size-limits-analytics

Conversation

@Emmycivity

@Emmycivity Emmycivity commented Aug 31, 2026

Copy link
Copy Markdown

Overview

Enforces explicit, bounded response-size limits on public analytics endpoints and collection detail routes, introduces a shared limit validation helper, ensures database queries never allocate unbounded collections, and guarantees error responses do not leak database or internal details.

Scope note (resubmission): this PR was split from the earlier #427 to keep the change limited to bounded response behavior and its tests. The previously bundled webhook/outbox/jobs/relations/auth-schema additions have been removed.

Related Issue

Closes #417

Changes

Analytics Limits & Public Endpoints

  • [ADD] web/src/lib/analytics-limits.ts — shared parseAnalyticsLimit helper validating positive integer limits and enforcing route-specific maximums (HTTP 400 on over-limit or malformed values).
  • [MODIFY] web/src/app/api/ecosystem-intelligence/route.ts — limit param validation (default 10, max 50) and bounded detail collections.
  • [MODIFY] web/src/app/api/talos/[id]/exposure/route.ts — limit validation (default 25, max 100) and query bounding, replacing silent clamping with explicit 400 validation.
  • [MODIFY] web/src/app/api/talos/[id]/exposure/alerts/route.ts — limit validation (default 25, max 100) and bounded query/alert results.
  • [MODIFY] web/src/app/api/talos/[id]/financial-summary/route.ts — limit validation (default 20, max 100) and bounded spending/playbook rows.
  • [MODIFY] web/src/app/api/talos/[id]/financial-projection/route.ts — bounded patron query and sanitized 500 responses.
  • [MODIFY] web/src/app/api/talos/[id]/patrons/route.ts — limit validation (default 50, max 100) and query limit.
  • [MODIFY] web/src/app/api/talos/[id]/dividends/route.ts — limit query param (default 50, max 100).
  • [MODIFY] web/src/app/api/talos/[id]/revenue/route.ts — limit validation (default 50, max 100).
  • [MODIFY] web/src/app/api/proposals/route.ts — limit param (default 50, max 100) and query limit.
  • [MODIFY] web/src/app/api/dashboard/route.ts — bounded relational sub-queries and sanitized timeout errors.

Tests

  • [ADD] web/tests/analytics-limits.unit.test.ts — 29 unit tests.
  • [ADD] web/tests/analytics-route-limits.unit.test.ts — 33 tests for route-level limit validation and error-detail hiding.
  • [MODIFY] web/src/app/api/talos/[id]/exposure/__tests__/route.test.ts — default/max/over-limit/malformed limit cases.
  • [MODIFY] web/src/app/api/talos/[id]/exposure/alerts/__tests__/route.test.ts — default/max/over-limit/malformed + alert bounding.
  • [MODIFY] web/src/app/api/talos/[id]/financial-summary/__tests__/route.test.ts — limit cases.
  • [MODIFY] web/tests/ecosystem-intelligence.test.ts — limit bounding/error cases.

Verification

  • Analytics suites: 6 test files, 119 tests passing.
  • Full web unit suite (excluding e2e/load): identical 118 pre-existing failures as main (infra/DB-dependent) with 88 additional passing tests (all analytics). A full tsc run shows no new type errors (232 errors vs 233 on main; the one reduction is the missing withTraceContext import in the revenue route, which this change restores).
  • Type-check introduced by this change: clean on all modified/new files.
Acceptance Criteria Status
Every affected endpoint has an explicit default and maximum limit Enforced across exposure, alerts, financial summary/projection, patrons, dividends, revenue, proposals, ecosystem intelligence, dashboard
Server never allocates an unbounded collection based on user input Bounded database queries and sliced response arrays
Existing response fields remain backward compatible Preserved envelopes, metadata, and aggregate calculations
Tests cover default, maximum, over-limit, and malformed-limit behavior 119 tests across 6 analytics suites
Error responses do not expose database or implementation details Sanitized across all affected routes

@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@Emmycivity is attempting to deploy a commit to the Cankat's projects Team on Vercel.

A member of the Team first needs to authorize it.

…enliven17#417)

- Implement shared parseAnalyticsLimit validation helper with positive integer checks and upper-bound enforcement
- Apply route-specific limit validation and database query bounds on exposure, alerts, financial-summary, financial-projection, patrons, dividends, revenue, proposals, and ecosystem-intelligence
- Sanitize error envelopes to prevent internal database and implementation leakage
- Add comprehensive test coverage for default, maximum, over-limit, and malformed parameter handling
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.

security(web): enforce response-size limits on public analytics endpoints

1 participant