Skip to content

SQL safety: unallowlisted table identifier + unescaped LIKE wildcards + unscoped by-id ops #19

Description

@codenamekt

Summary

Two SQL-safety bugs in the data layer: an identifier interpolated without an allowlist, and unescaped LIKE wildcards on caller-influenced text.

Findings

increment_recall_counts interpolates the table name (high)

store.py:2060-2071table is interpolated into SQL via f-string with no allowlist. It's a public method on MemoryStore; a caller passing a derived table name gets arbitrary SQL (table = "memory_entries; DROP TABLE memory_entries; --" runs as a multi-statement via psycopg). Internal callers pass literals today, but nothing enforces it.

  • Fix: assert table in {"memory_entries","conversations","delegations"}.

replace()/remove() don't escape LIKE wildcards (medium)

store.py:917, 942, 974 — build LIKE '%' || old_text || '%' without escaping %/_. old_text comes from memory-tool arguments (conversation-influenced).

  • Scenario: remove(old_text="%") deletes every entry in the (agent, target) scope; _ matches any character, so replaces/removes hit unintended rows.
  • Fix: escape \ % _ and add ESCAPE '\'.

Related: by-id operations lack agent scoping (medium)

store.py:1298-1315, 2024-2058fetch_full, confirm_entry, reject_entry take a bare sequential id with no agent_identity filter. (Cross-referenced from the security issue; fix location is the store layer.)

Suggested direction

Allowlist the table identifier; escape LIKE metacharacters; add agent_identity scoping to by-id reads/mutations.

Filed from the 2026-07 codebase review.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: securityArea: securitybugSomething isn't workingcode-reviewFiled from the 2026-07 codebase reviewpriority: criticalMust fix; data loss, security, or broken release

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions