Skip to content

[🐛 Bug]: A preset filter searching for the word "contains" silently searches for "includes" #6699

Closed

Description

@dngr2

Describe the bug

sanitizeCELIntoJS translates the CEL contains operator into JavaScript includes before the filter expression is evaluated. It does so with an unanchored global replace:

keep-ui/features/presets/presets-manager/lib/eval-with-context.ts:13

let jsExpression = celExpression.replace(/contains/g, "includes");

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:

  1. The search term is rewritten. A filter looking for alerts whose description contains the word "contains" instead matches alerts containing "includes".
  2. 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.

Activity

  1. dosubot commented on Aug 16, 2026

    @dosubot

    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].

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about keep Share Dosu with your team

  2. added
    Bug
    on Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions