Skip to content

fix(api): refactors the SQL LIKE pattern escaping logic to use a centralized utility function, ensuring consistent and secure handling of special characters across all database queries. - #38

Open
tomerqodo wants to merge 4 commits into
sentry_combined_20260121_augment_sentry_coderabbit_1_base_fixapi_refactors_the_sql_like_pattern_escaping_logic_to_use_a_centralized__utility_function_ensuring_consistent_and_secure_handling_of_specialfrom
sentry_combined_20260121_augment_sentry_coderabbit_1_head_fixapi_refactors_the_sql_like_pattern_escaping_logic_to_use_a_centralized__utility_function_ensuring_consistent_and_secure_handling_of_special
Open

fix(api): refactors the SQL LIKE pattern escaping logic to use a centralized utility function, ensuring consistent and secure handling of special characters across all database queries.#38
tomerqodo wants to merge 4 commits into
sentry_combined_20260121_augment_sentry_coderabbit_1_base_fixapi_refactors_the_sql_like_pattern_escaping_logic_to_use_a_centralized__utility_function_ensuring_consistent_and_secure_handling_of_specialfrom
sentry_combined_20260121_augment_sentry_coderabbit_1_head_fixapi_refactors_the_sql_like_pattern_escaping_logic_to_use_a_centralized__utility_function_ensuring_consistent_and_secure_handling_of_special

Conversation

@tomerqodo

Copy link
Copy Markdown

Benchmark PR from qodo-benchmark#431

NeatGuyCoding and others added 4 commits January 21, 2026 15:54
…ralized

utility function, ensuring consistent and secure handling of special characters
across all database queries.

Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com>
…logic

Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com>
case "not contains":
filters.append(json_field.notlike(f"%{value}%"))
escaped_value = escape_like_pattern(str(value))
filters.append(json_field.notlike(f"%{escaped_value}%"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The notlike method call is missing the escape="\\" parameter, causing incorrect filtering when special characters like _ or % are used in a "not contains" filter.
Severity: MEDIUM

Suggested Fix

Add the escape="\\" parameter to the notlike call on line 1207 to ensure the database correctly handles escaped characters. Change filters.append(json_field.notlike(f"%{escaped_value}%")) to filters.append(json_field.notlike(f"%{escaped_value}%", escape="\\")).

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: api/core/rag/retrieval/dataset_retrieval.py#L1207

Potential issue: The code escapes special characters (`%`, `_`, `\`) for SQL LIKE
queries, but the `notlike` method call on line 1207 is missing the required
`escape="\\"` parameter. While other similar `like` and `ilike` calls in the same file
correctly include this parameter, its absence in the `notlike` call means the database
will not interpret escaped characters correctly. This causes "not contains" filters with
special characters to return incorrect results and introduces a potential wildcard
injection vulnerability.

Did we get this right? 👍 / 👎 to inform future reviews.

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