Uh oh!
There was an error while loading. Please reload this page.
fix: sanitize array elements in list_condition_expr to prevent SQL injection - #1713
Conversation
…jection Closesparseablehq#1688 The list_condition_expr function was interpolating inner_value directly into ARRAY[...] SQL expressions without any escaping or validation, allowing crafted input like `1] OR 1=1; --` to break out of the ARRAY context and inject arbitrary SQL. scalar_condition_expr already handled escaping correctly (single-quote escaping, numeric/boolean validation). This commit brings list_condition_expr to the same standard by adding a sanitize_array_elements helper that: - Splits the value by comma - Validates each element as numeric, boolean, or a properly single-quoted string - Rejects any element containing bracket characters `[` or `]` that could escape the ARRAY literal context - Returns an Err if any element fails validation
CLA Assistant Lite bot: I have read the CLA Document and I hereby sign the CLA Prabhakar Singh seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds quote-aware list parsing and SQL literal sanitization in ChangesArray Element Sanitization
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
prabhaks
commented
Jul 2, 2026
I have read the CLA Document and I hereby sign the CLA |
The bare unquoted string branch was rejecting valid values containing spaces, colons, slashes, etc. due to an alphanumeric-only allowlist. This is inconsistent with scalar_condition_expr which accepts any string and simply escapes single quotes. The bracket character check at the top already covers the actual injection vector, making the allowlist redundant. Now mirrors scalar_condition_expr: escape single quotes and wrap in single quotes, no character allowlist.
The contains("' OR '") check was a false negative — the correctly
escaped output 'foo'' OR ''1''=''1' still contains that substring
as part of the doubled quotes. The assert_eq on the exact escaped
string is already sufficient to prove injection safety; drop the
redundant contains check.prabhaks
commented
Jul 2, 2026
@nikhilsinhaparseable please review the changes whenever you get the chance. Tested locally - runs fine! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/alerts/alerts_utils.rs`:
- Around line 473-514: The array sanitizer in sanitize_array_elements currently
splits on every comma, which breaks quoted list items containing commas. Update
the parsing logic to be quote-aware so elements like single-quoted strings with
embedded commas stay intact, while preserving the existing trimming, bracket
rejection, and re-quoting behavior used by sanitize_array_elements and
scalar_condition_expr.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Uh oh!
There was an error while loading. Please reload this page.
The previous value.split(',') broke on quoted elements that contained
commas, e.g. 'New York, NY' was split into two invalid fragments.
Replace it with a hand-rolled quote-aware splitter that:
- Treats '' inside a quoted string as an escaped quote (not a close)
- Only splits on commas that appear outside of single-quoted strings
- Rejects unterminated quoted strings with a clear error
- Preserves all existing trimming, bracket-rejection, and re-quoting
behaviour unchanged
New tests cover: comma inside a quoted element, comma inside a quoted
element that also contains a doubled-quote escape, mixed quoted and
numeric elements, and an unterminated quote error.Replace `.map(|(b, _)| b).unwrap_or(value.len())` with `.map_or(value.len(), |(b, _)| b)` in all three byte-offset lookups inside split_array_elements. Fixes: - clippy::unwrap_or_else_default (unwrap_or followed by a function call) - clippy::map_unwrap_or (.map().unwrap_or() on Option)
prabhaks
commented
Jul 3, 2026
Do you know why the CI(coverage and load test) is taking lot of time? |
nitisht
commented
Jul 4, 2026
Looks good - thanks for the PR @prabhaks
For external contributions we require a manual approval of the CI workflow, probably that is why. |
Uh oh!
There was an error while loading. Please reload this page.
Summary
Fixes#1688
list_condition_exprinsrc/alerts/alerts_utils.rswas interpolatinginner_valuedirectly intoARRAY[...]SQL expressions without any escaping or validation. This allowed crafted input like1] OR 1=1; --to break out of theARRAYcontext and inject arbitrary SQL.scalar_condition_exprright below it already handled this correctly (single-quote escaping, numeric/boolean validation). This PR bringslist_condition_exprto the same standard.Changes
Added a
sanitize_array_elementshelper that:[or]that could escape theARRAY[...]contextErrdescribing the first offending element if validation failslist_condition_exprnow passesinner_valuethrough this helper before interpolating it into the SQL format string.Testing
1] OR 1=1; --now returns an error instead of being interpolatedsanitize_array_elementsandlist_condition_exprReferences
Summary by CodeRabbit