Skip to content

fix(security): escape LIKE wildcards in namespace path resolution - #10

Merged
alash3al merged 1 commit into
alash3al:mainfrom
rudi193-cmd:fix/like-wildcard-escape
May 29, 2026
Merged

alash3al merged 1 commit into
alash3al:mainfrom
rudi193-cmd:fix/like-wildcard-escape

Conversation

@rudi193-cmd

Copy link
Copy Markdown
Contributor

Summary

Revives and extends closed PR #5.

Namespace slugs allow _ in path segments, but PostgreSQL LIKE treats _ as a single-character wildcard. The descendant lookup in resolveNamespaceIDWithDescendants used slug LIKE $path || '/%' without escaping, so a path like /foo_bar could match /fooXbar/... and pull in unrelated namespace IDs — affecting recall, consolidate, goals, facts, and any API that resolves namespace descendants.

This PR:

  • Adds escapeLikePattern() and uses LIKE ... ESCAPE '\' on the descendant query
  • Adds internal/brain/brain_test.go — first unit tests in the repo — covering underscore, percent, and backslash escaping

Test plan

  • go test ./internal/brain/ -v (escape + descendant pattern helpers)
  • Manual: create namespaces /foo_bar and /fooXbar/baz; query descendants of /foo_bar — should not include /fooXbar/baz

Related: docs PR #9 remains open separately (Ollama setup).

Made with Cursor

Slug segments allow underscores, which PostgreSQL treats as single-char
wildcards in LIKE. Without escaping, /foo_bar could match /fooXbar/...
and leak namespace data across recall, consolidate, and goals.

Adds escapeLikePattern + ESCAPE '\' on the descendant query and unit
tests (first *_test.go in the repo). Revives closed PR #5.
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.

2 participants