Skip to content

pg: fix list_key_versions interpreting keys as patterns - #114

Open
phlip9 wants to merge 1 commit into
lightningdevkit:mainfrom
phlip9:phlip9/fix-list-key-versions
Open

pg: fix list_key_versions interpreting keys as patterns#114
phlip9 wants to merge 1 commit into
lightningdevkit:mainfrom
phlip9:phlip9/fix-list-key-versions

Conversation

@phlip9

@phlip9 phlip9 commented Sep 2, 2026

Copy link
Copy Markdown

Using key LIKE $3 unescaped tells Postgres to interpret the requested key prefix as a pattern, which means %, _, and \ are interpreted as wildcards and character escapes in the original prefix rather the actual intended literal prefix.

This means a list_key_versions(key="foo_bar", ..) actually includes foo1bar, which definitely does not seem intentional.

A better approach is to just use starts_with(key, $3), which the query planner understands better and doesn't require any escaping.

Using `key LIKE $3` unescaped tells Postgres to interpret the requested
key prefix as a pattern, which means %, _, and \ are interpreted as
wildcards and character escapes in the original prefix rather the actual
intended literal prefix.

This means a `list_key_versions(key="foo_bar", ..)` actually includes
`foo1bar`, which definitely does not seem intentional.

A better approach is to just use `starts_with(key, $3)`, which the query
planner understands better and doesn't require us to do any escaping.
@ldk-reviews-bot

ldk-reviews-bot commented Sep 2, 2026

Copy link
Copy Markdown

I've assigned @tankyleo as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@phlip9

phlip9 commented Sep 2, 2026

Copy link
Copy Markdown
Author

cc @tnull (can't add reviewers in the sidebar 😢)

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