Skip to content

fix: nested _where filters fail open when intermediate field is missing#1744

Open
cyphercodes wants to merge 1 commit intotypicode:mainfrom
cyphercodes:fix-nested-where-fail-open
Open

fix: nested _where filters fail open when intermediate field is missing#1744
cyphercodes wants to merge 1 commit intotypicode:mainfrom
cyphercodes:fix-nested-where-fail-open

Conversation

@cyphercodes
Copy link
Copy Markdown

Fixes #1731

Problem

Nested _where object filters currently fail open when the intermediate field does not exist on the target object or is not an object.

For example, with data { title: 'a' }:

  • { title: { eq: 'zzz' } } correctly returns empty (no match)
  • { title: { nested: { eq: 'zzz' } } } incorrectly returns all rows (fail-open bug)

Solution

Added hasKnownOperatorsAtAnyLevel() helper to detect when a nested object contains known operators at any depth. If it does, and the field is not an object, the filter now correctly returns false.

This preserves the existing fail-open behavior for unknown operators while fixing the fail-closed behavior for nested predicates on non-object fields.

Changes

  • Added hasKnownOperatorsAtAnyLevel() helper function in src/matches-where.ts
  • Modified nested object handling to check for operators at any level
  • Added regression tests for the specific bug cases

Testing

All 130 tests pass, including 3 new regression tests for this specific issue.

Fixes typicode#1731

When using nested object predicates like { title: { nested: { eq: 'zzz' } } },
the filter would incorrectly return all rows if the intermediate field (title)
was not an object. This happened because the code would 'continue' instead of
returning false when the field was missing or not an object.

The fix adds a hasKnownOperatorsAtAnyLevel() helper to detect when a nested
object contains known operators at any depth. If it does, and the field is not
an object, the filter now correctly returns false.

This preserves the existing fail-open behavior for unknown operators while
fixing the fail-closed behavior for nested predicates on non-object fields.

- Added hasKnownOperatorsAtAnyLevel() helper function
- Modified nested object handling to check for operators at any level
- Added regression tests for the specific bug cases
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.

Fail-open nested _where filtering

1 participant