Skip to content

security: harden API input validation and error messages#22

Merged
marinone94 merged 1 commit into
mainfrom
fix/api-hardening
Mar 11, 2026
Merged

security: harden API input validation and error messages#22
marinone94 merged 1 commit into
mainfrom
fix/api-hardening

Conversation

@marinone94

Copy link
Copy Markdown
Owner

Summary

  • Input validation: sort_by as Literal["relevance", "newest", "dataset"], collection name pattern ^[a-z0-9_]{1,64}$, agent input max_length and pattern constraints
  • Error sanitization: internal stack traces/config details removed from HTTP error responses in search, export, and MCP server endpoints
  • Analytics privacy: get_event_stats() scoped by user_id; anonymous callers get aggregate counts only (no raw query strings)
  • Session ID validation: regex ^[0-9a-zA-Z\-_]{1,100}$ prevents arbitrary string storage
  • Export filename: regex sanitization prevents path traversal in Content-Disposition
  • MCP server: sanitized error messages in semantic/hybrid search fallback

Note: Depends on #20 for get_optional_user import in analytics and auth-related test fixtures.

Test plan

  • test_search_sort_invalid_rejected — invalid sort_by returns 422
  • test_langfuse_without_credentials_returns_502 — sanitized error message
  • test_get_event_stats_with_events — uses user_id scoping
  • test_get_event_stats_anonymous_hides_queries — privacy test
  • All 523 tests passing

🤖 Generated with Claude Code

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 10, 2026

Copy link
Copy Markdown

Deploying cherry-evals with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3b535fe
Status: ✅  Deploy successful!
Preview URL: https://f101f97e.cherry-evals.pages.dev
Branch Preview URL: https://fix-api-hardening.cherry-evals.pages.dev

View logs

marinone94 added a commit that referenced this pull request Mar 11, 2026
…#23, #25

Mark 17 findings as fixed/mitigated, update executive summary,
reorganize remediation roadmap into done/immediate/before-launch/after-launch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Pydantic: sort_by as Literal type, collection name pattern-validated
- Agent inputs: max_length on description/format, pattern on hf_dataset_id
- Error sanitization: remove internal details from HTTP responses (search,
  export, MCP server)
- Analytics: scoped by user_id, anonymous callers don't see raw queries
- Events: session_id validated against alphanumeric regex
- Export: filename sanitized with regex to prevent path traversal
- MCP server: sanitized error messages in semantic/hybrid search
- Tests updated for new validation behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
marinone94 added a commit that referenced this pull request Mar 11, 2026
…#23, #25

Mark 17 findings as fixed/mitigated, update executive summary,
reorganize remediation roadmap into done/immediate/before-launch/after-launch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@marinone94
marinone94 merged commit 3f834de into main Mar 11, 2026
4 checks passed
@marinone94
marinone94 deleted the fix/api-hardening branch March 11, 2026 05:53
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