Skip to content

fix(server): stop % and _ in a forget id from acting as LIKE wildcards (#1435) - #1436

Merged
ajianaz merged 1 commit into
developfrom
fix/forget-id-wildcard
Oct 12, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/forget-id-wildcard

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

What

Two layers, both needed:

  • Root cause: Store::resolve_id_prefix builds LIKE '<prefix>%' and now escapes %, _ and the escape character (ESCAPE '\'), so an id prefix is literal text for every caller (HTTP forget, the CLI contradiction commands, anything else that resolves a short id).
  • Validation: the HTTP forget policy (ForgetPolicy::HTTP) now uses IdCharset::HexAndDash, the same rule MCP has had since fix: align /import size limit and harden /mcp & id handling #1328. A non-hex id is 400 Invalid memory id '<id>' (expected a UUID or hex prefix).

Why

Closes #1435. DELETE /forget?id=%25 (the query value is not percent-decoded) matched every memory whose id contains "25" and deleted it when exactly one matched. Any write token could trigger it with a malformed id. Found by the differential run of the typed-request refactor (#1343): the pre-refactor server sometimes returned 200 forgotten for that request and sometimes 404 or "ambiguous", depending on which random UUIDs contained "25". MCP was never affected.

Testing

  • fmt, clippy -D warnings, cargo test --workspace, vecq-only core lib tests (721) green; docgen leaves docs/ clean
  • New tests, both verified to FAIL against the old behaviour: resolve_id_prefix_treats_wildcards_literally (store level: real prefixes still resolve, shared prefix still ambiguous, %, _, %25, ab_d, a%, \, abcd% match nothing) and charset_check_applies_to_every_surface_and_wildcards_never_match (HTTP and MCP reject %, _, %25, \, braces and urn: ids; a policy that skips the charset check still cannot wildcard; a real 8-char prefix resolves). The old test that pinned "HTTP lets % resolve" (charset_check_is_mcp_only) was rewritten
  • End to end with the built uteke-serve, 12 memories: 12 wildcard variants (%25, %, _, __, %2525, a%25, 1%, %5F, abc%, 2_, \) all return 400 and the memory count stays 12; a valid 12-char prefix returns 200 {"forgotten": ...} (12 to 11)
  • Behaviour notes: HTTP urn:uuid:... and {...} ids were 404 before (they failed the existence check) and are now 400; HTTP/CLI forget by tag and every valid hex id or prefix are unchanged. Percent-decoding of query values is a separate, pre-existing mismatch and is not changed here

🤖 Generated with Claude Code

#1435)

resolve_id_prefix now escapes %, _ and the escape character, so an id prefix is
never a pattern for any caller, and the HTTP forget policy validates the id like
MCP (hex digits and '-', 400 otherwise). Before, DELETE /forget?id=%25 matched
every memory whose id contains "25" and deleted it when exactly one matched.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 33c3e30 into develop Oct 12, 2026
15 checks passed
@ajianaz
ajianaz deleted the fix/forget-id-wildcard branch October 12, 2026 07:43
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(server): DELETE /forget treats % and _ in the id as LIKE wildcards and can delete a memory it was not asked for

1 participant