Skip to content

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

Draft
sonnymay wants to merge 2 commits into
mainfrom
claude/sleepy-lamport-pentp7
Draft

sonnymay wants to merge 2 commits into
mainfrom
claude/sleepy-lamport-pentp7

Conversation

@sonnymay

Copy link
Copy Markdown
Owner

Summary

Test plan

  • Added backend/test_ai.py covering that a crafted ticket_id (with &, ), ,) is percent-encoded before reaching db_get, for both _fetch_ticket and _fetch_notes.
  • python -m pytest (46 passed)
  • python -m ruff check . / ruff format --check . clean

Note for maintainer

This repo already has several open draft PRs (#20–#26) proposing the identical fix for this same file, none merged. Recommend merging this one (or the earliest of that batch) and closing the rest as duplicates.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JBr5TgDKjyVGFYCtdKAEJn


Generated by Claude Code

…ai.py

_fetch_ticket and _fetch_notes built PostgREST filter strings with raw
f-string interpolation ("id=eq.{ticket_id}", "ticket_id=eq.{ticket_id}"),
reachable from POST /ai/suggest via AISuggestRequest.ticket_id. This is
the same injection class already fixed in main.py/database.py (comma,
parentheses, and query-string delimiters are structural in PostgREST and
were never escaped), just missed in ai.py.

Route both values through database.escape_filter_value, already used by
the other id-based lookups. Add test_ai.py covering that a crafted
ticket_id is escaped rather than passed through.

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

vercel Bot commented Sep 17, 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 25, 2026 6:26am UTC

This branch was successfully deployed

1 active deployment
Preview — cc578656 Deployed Sep 25, 2026 by vercel[bot]
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