Skip to content

fix: escape ticket_id before interpolating into PostgREST filters in ai.py - #24

Draft
sonnymay wants to merge 1 commit into
mainfrom
claude/sleepy-lamport-k64ipz
Draft

sonnymay wants to merge 1 commit into
mainfrom
claude/sleepy-lamport-k64ipz

Conversation

@sonnymay

Copy link
Copy Markdown
Owner

Summary

  • #18/#19 added escape_filter_value() to guard every PostgREST filter built in main.py against query-parameter injection (a crafted id could append extra filter clauses, e.g. widen a select or override a filter).
  • ai.py's _fetch_ticket and _fetch_notes — reachable via POST /ai/suggest with a user-supplied ticket_id — were missed and still interpolated the raw value directly into id=eq.{ticket_id} / ticket_id=eq.{ticket_id}&... filter strings.
  • This PR applies the same escape_filter_value() guard to both call sites in ai.py.

Test plan

  • Added backend/test_ai.py with regression tests mirroring the existing injection-guard tests in test_database.py/test_main.py, verifying a ticket_id containing &-delimited PostgREST query syntax can no longer inject extra params.
  • pytest backend/test_ai.py backend/test_database.py backend/test_main.py — all pass except one pre-existing, unrelated failure (test_get_headers_uses_supabase_key) caused by SUPABASE_URL not being set in this sandbox; reproduces identically on unmodified main.
  • ruff check backend/ai.py backend/test_ai.py — clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MfAUz5zxhP1oHqmUFFghyk


Generated by Claude Code

…ai.py

_fetch_ticket and _fetch_notes built PostgREST filter strings by
interpolating the user-supplied ticket_id from /ai/suggest directly,
missing the same escape_filter_value() guard that #18 and #19 already
applied to every filter in main.py. A crafted ticket_id could inject
extra query parameters (e.g. widen the select or override filters) into
the AI suggestion lookups. Add regression tests mirroring the existing
injection-guard tests in test_database.py/test_main.py.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MfAUz5zxhP1oHqmUFFghyk
@vercel

vercel Bot commented Sep 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
supportops Ready Ready Preview Sep 14, 2026 2:07pm UTC

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