Skip to content

Security: SQL injection risk in get_filter_string / list_condition_expr (alerts_utils.rs) #1688

Closed

Description

@coderabbitai

Summary

The get_filter_string function in src/alerts/alerts_utils.rs does not properly escape user-provided values when building SQL filter strings. Specifically, in list_condition_expr, the inner_value parameter is directly interpolated into SQL expressions (e.g., ARRAY[{inner_value}]) without escaping or sanitization, allowing crafted input to break out of the ARRAY context and inject arbitrary SQL.

Steps to Reproduce / Exploit

A user-supplied condition value such as 1] OR 1=1; -- would be embedded verbatim, producing:

ARRAY[1] OR 1=1; --]

which alters the query logic.

The resulting filter string is then directly concatenated into WHERE clauses (e.g., in the log context query builder added in PR #1687), rather than being passed as a parameterized binding.

Affected Files

  • src/alerts/alerts_utils.rs — get_filter_string, list_condition_expr, scalar_condition_expr

Recommended Fix

  • Escape all user-supplied string values before interpolation (e.g., escape single quotes, bracket characters used in ARRAY literals).
  • Or refactor to use parameterized / prepared query execution instead of raw string concatenation.

References

/cc @nikhilsinhaparseable

Activity

  1. coderabbitai commented on Jun 18, 2026

    @coderabbitai
    ContributorAuthor
    🔗 Related PRs

    #1304 - fix: sql query to fetch distinct values in datasets API [merged]
    #1355 - null checks [merged]
    #1357 - fix: filter with LIKE operators [merged]
    #1379 - fix: handle proper SQL variable type for operators [merged]
    #1532 - fix: counts api [merged]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. prabhaks commented on Jul 1, 2026

    @prabhaks
    Contributor

    Hi @nikhilsinhaparseable ! I had a look at this and the fix is pretty straightforward - the vulnerability is isolated to list_condition_expr in alerts_utils.rs. Interestingly, scalar_condition_expr right below it already handles escaping correctly (single-quote escaping, numeric validation, etc.), so list_condition_expr just needs the same treatment.

    The plan would be to add a small sanitize_array_elements helper that splits the array value by comma, validates each element as either a numeric, boolean, or properly single-quoted string, and rejects anything that doesn't fit - like bracket characters that could break out of the ARRAY[...] context. Then just run inner_value through that before interpolating it into the format string.

    It's a single-file change and I can have a PR up pretty quickly. Would it be okay if I took this one?

  3. nikhilsinhaparseable commented on Jul 2, 2026

    @nikhilsinhaparseable
    Member

    Hi @prabhaks thank you for explaining the issue and the plan to fix.
    I would love to review the PR. Please give it a shot.

  4. added a commit that references this issue on Jul 2, 2026
    9a4b35a
  5. added a commit that references this issue on Jul 4, 2026
    d2507cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions