fix(plugins): reject a storage range filter with no defined bound - #9
Merged
vedanshujain merged 1 commit intoSep 12, 2026
Merged
Conversation
buildCondition pushes only the bounds that are defined, so a filter whose
every bound is undefined returned an empty SQL string. buildWhereClause
joined that empty string into the clause, which dropped the predicate
entirely.
The reachable shape is a bound built from an optional value:
const since = options.since; // string | undefined
await storage.query({ where: { timestamp: { gte: since } } });
That type-checks, because each bound on RangeFilter is optional. query()
and count() then returned every row in the collection, and updateIf()
applied its write with no guard — a guarded decrement could drive a
counter past the bound the caller asked for, which is the oversell
updateIf exists to prevent. A second field alongside the empty one
emitted a dangling AND and failed to parse.
buildCondition now throws StorageQueryError naming the field, and
buildWhereClause skips any condition contributing no SQL.
Callers that mean "match unconditionally" omit the field instead.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NK2NYBPGxwwzgHf7KfQRGM
18 tasks
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.
What does this PR do?
Targets
feat/plugin-storage-updateif(emdash-cms#2169) rather thanmain, because it was found while reviewing that branch.buildConditionpushes only the bounds that are defined, so a range filter whose every bound isundefinedreturned an empty SQL string.buildWhereClausethen joined that empty string into the clause, dropping the predicate entirely.The reachable shape is a bound built from an optional value:
That type-checks, because every bound on
RangeFilteris optional. Verified against the pre-fix code — three rows seeded, filter{ stock: { gte: undefined } }:So
query()andcount()returned the whole collection, andupdateIf()applied its write with no guard at all:That last one is the oversell
updateIfexists to prevent. A second field alongside the empty one emits a danglingANDand fails to parse.buildConditionnow throwsStorageQueryErrornaming the field, andbuildWhereClauseskips any condition contributing no SQL. Callers that mean "match unconditionally" omit the field.Note this changes behavior of the already-released
query()andcount(): a filter that previously matched everything now throws. That is the point of the fix — the old behavior was silent and failed open — but it is a behavior change on a shipped API, so it is called out in the changeset.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change) — fullpackages/coresuite, 6554 passed / 10 skipped / 0 failedpnpm formathas been runAI-generated code disclosure
Screenshots / test output
Not applicable — no UI change.
Three regression tests, each confirmed to fail before the fix:
storage-query.test.ts—buildConditionthrows for an all-undefinedrange filter;buildWhereClausenever emits a danglingAND.storage.test.ts—query()rejects the filter instead of returning every row (the shipped path).storage-updateif.test.ts—updateIf()throws instead of writing unguarded, and the row is unchanged.