Repository navigation
fix(security): escape LIKE wildcards in namespace path resolution - #10
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Revives and extends closed PR #5.
Namespace slugs allow
_in path segments, but PostgreSQLLIKEtreats_as a single-character wildcard. The descendant lookup inresolveNamespaceIDWithDescendantsusedslug LIKE $path || '/%'without escaping, so a path like/foo_barcould match/fooXbar/...and pull in unrelated namespace IDs — affecting recall, consolidate, goals, facts, and any API that resolves namespace descendants.This PR:
escapeLikePattern()and usesLIKE ... ESCAPE '\'on the descendant queryinternal/brain/brain_test.go— first unit tests in the repo — covering underscore, percent, and backslash escapingTest plan
go test ./internal/brain/ -v(escape + descendant pattern helpers)/foo_barand/fooXbar/baz; query descendants of/foo_bar— should not include/fooXbar/bazRelated: docs PR #9 remains open separately (Ollama setup).
Made with Cursor