You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[🐛 Bug]: A preset filter searching for the word "contains" silently searches for "includes" #6699
sanitizeCELIntoJS translates the CEL contains operator into JavaScript includes before the filter expression is evaluated. It does so with an unanchored global replace:
That rewrites those letters wherever they appear — including inside quoted search strings and inside identifiers.
To reproduce
Enter any of these as a preset / alerts filter:
Filter typed
What is actually evaluated
description.contains("contains")
description.includes("includes")
name.contains("this contains errors")
name.includes("this includes errors")
contains_pii == "true"
includes_pii == "true"
labels.contains_secret == "yes"
labels.includes_secret == "yes"
Expected behavior
The operator is translated; the search text and field names are left alone.
Actual behavior
Two distinct failures:
The search term is rewritten. A filter looking for alerts whose description contains the word "contains" instead matches alerts containing "includes".
A field is renamed out of existence. Any field or label whose name holds those letters — contains_pii, contains_secret — is rewritten to a name that doesn't exist, so the comparison evaluates against undefined and quietly matches nothing.
No error is raised in either case. The preset saves and filters normally, just against something the user never typed.
Additional context
The file has no tests.
This is the same class of silent rewriting as #6274, but a different code path — that one is the workflow YAML editor and is covered by #6647. This is the preset/alerts CEL evaluator.
A fix and tests are proposed in #6698: matching the call form .contains( rather than the bare word. That leaves one narrower case — a search string containing the literal .contains( — which needs a tokenizer rather than a regex to separate code from string literals.
Hi @dngr2! I'm Dosu and I'm helping the Keep team.
The bug is confirmed in the current code — line 13 of eval-with-context.ts uses /contains/g with no anchoring, exactly as described.
PR #6698 already addresses this by narrowing the replacement to match .contains( (the method call form) rather than the bare word [1]. That eliminates all four failure cases in the table. The PR also adds __tests__/eval-with-context.test.ts with 8 tests covering the fixed and pre-existing behaviours — 4 of those tests fail against the unfixed function, which confirms the tests pin the bug rather than just the implementation [1].
The one remaining gap noted in the PR — a search string containing the literal .contains( — would require a proper tokenizer to handle correctly, which the PR intentionally defers as a larger follow-on change [1].
Activity
dosubot commentedon Aug 16, 2026
Hi @dngr2! I'm Dosu and I'm helping the Keep team.
The bug is confirmed in the current code — line 13 of
eval-with-context.tsuses/contains/gwith no anchoring, exactly as described.PR #6698 already addresses this by narrowing the replacement to match
.contains((the method call form) rather than the bare word [1]. That eliminates all four failure cases in the table. The PR also adds__tests__/eval-with-context.test.tswith 8 tests covering the fixed and pre-existing behaviours — 4 of those tests fail against the unfixed function, which confirms the tests pin the bug rather than just the implementation [1].The one remaining gap noted in the PR — a search string containing the literal
.contains(— would require a proper tokenizer to handle correctly, which the PR intentionally defers as a larger follow-on change [1].To reply, just mention @dosu.
Docs are dead. Just use Dosu.