security: harden raw and literal variable rendering against injection#1
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
security: harden raw and literal variable rendering against injection#1devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
⚙️ Control Options:
|
1182d98 to
3ab939e
Compare
- render-raw-variable: reject values containing semicolons, line comment sequences (--), and block comment sequences (/*) to prevent multi-statement injection and comment-based query manipulation - render-literal-variable: reject backslash characters and NUL bytes in string values in addition to existing single-quote check, to prevent escape-based injection in non-PostgreSQL databases - Add tests for all new validation rules
1e8c5e2 to
7085cfe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds input validation guards to the two unsafe variable rendering paths (
/*!name*/raw variables and/*^name*/literal variables) to reduce the risk of SQL injection through these escape hatches.render-raw-variable(!sigil): Previously performed zero validation — any string was interpolated directly into SQL. Now rejects values containing:;(multi-statement injection)--(line comment sequences)/*(block comment sequences)render-literal-variable(^sigil): Previously only rejected single quotes. Now also rejects:\(backslash — escape-based injection in databases with non-standard string escaping, relevant for planned MySQL support per roadmap)Five new tests cover all added validation rules.
Review & Testing Checklist for Human
UNION SELECT, subqueries, andxp_cmdshellare not blocked. This is defense-in-depth, not a security boundary — verify this aligns with your expectations for the!sigil's threat model.standard_conforming_strings = on(default since PG 9.1), backslashes are literal characters, so legitimate values like file paths (C:\data) would now be rejected. Decide if this trade-off is acceptable or if the check should be deferred until non-PostgreSQL support is added.--rejection in raw variables could false-positive on edge cases. While--is universally a SQL line comment, verify there's no legitimate raw-variable use case in your codebase that would contain this sequence (e.g., unusual identifier patterns).:unsafe? trueoption should exist.bb testlocally to confirm all 81+ tests pass (the new tests exercise exception paths, so they should be deterministic).Notes
!sigil is documented in the spec as "safety is intentionally delegated to the developer" — these guards are best-effort defense-in-depth, not a replacement for developer diligence. The blocklist targets patterns that have no legitimate use in typical raw-variable contexts (ORDER BY columns, table/column names, etc.).ex-infowith:parameterand:valuein the data map).Link to Devin session: https://app.devin.ai/sessions/c4ff79c8728b4771ad2ab36bfe3e71cf
Requested by: @hatappo