Skip to content

fix(crewai-tools): block SELECT INTO in NL2SQLTool read-only mode - #9670

Open
Vidit Ostwal (Vidit-Ostwal) wants to merge 3 commits into
mainfrom
viditostwal/oss-262-medium-nl2sqltool-read-only-mode-allows
Open

Vidit Ostwal (Vidit-Ostwal) wants to merge 3 commits into
mainfrom
viditostwal/oss-262-medium-nl2sqltool-read-only-mode-allows

Conversation

@Vidit-Ostwal

Copy link
Copy Markdown
Member

Fixes OSS-262 (GHSA-5gjp-r3m5-5w96).

Problem

NL2SQLTool read-only mode only validated the leading keyword, so SELECT ... INTO OUTFILE/DUMPFILE could write files on the DB host, and SELECT ... INTO new_table could create tables.

Fix

  • Added _detect_into_clause, which ignores string literals, and call it for SELECT/SHOW/DESCRIBE/EXPLAIN/WITH statements when allow_dml=False.
  • INTO @var (MySQL session variable) stays allowed.
  • Behavior with allow_dml=True is unchanged.

Tests

Added TestSelectIntoBlocked (blocked variants, benign queries, allow_dml=True).

🤖 Generated with Claude Code

@strix-security

strix-security Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: Hardens `NL2SQLTool`'s read-only mode so `SELECT ... INTO OUTFILE`/`DUMPFILE` and `SELECT ... INTO new_table` are rejected when `allow_dml=False`, while keeping MySQL `INTO @​var` allowed. Adds tests for blocked and benign forms.

Review summary

The PR adds an INTO-clause gate to NL2SQLTool's read-only path: INTO OUTFILE/DUMPFILE are matched on the raw statement, and any other INTO is matched after blanking single-quoted literals or, when the statement contains backslash, double-quote or backtick quoting, on the raw text. The OUTFILE/DUMPFILE file-write half of the earlier quote-mis-parse finding is genuinely closed. One gap remains in the new fail-closed list: PostgreSQL dollar-quoted literals ($$'$$, $q$'$q$) are not treated as ambiguous quoting, so the single-quote blanker still disagrees with the server lexer and SELECT ... INTO new_table is accepted in read-only mode; because read-only mode never commits, the created table is rolled back, so it stays a low-impact control bypass. Reviewed alongside: the new tests and the generated tool spec metadata.

Ruled out (4)
  • Do boolean EXPLAIN option spellings such as `EXPLAIN (ANALYZE true) DELETE` let read-only mode execute write statements?
    The option-parsing gap is real but sits in `_resolve_explain_command`, which the PR neither modifies nor reaches, and no commit happens with `allow_dml=False` (the session is closed and rolled back), so nothing persists and the new INTO gate still catches the file-write forms.
  • Does the SingleStore search tool's prefix-only SELECT/SHOW guard let an agent write files or run multi-statement SQL?
    That file is not changed or reached by this PR, and the query text comes from the agent running with the operator's own configured database credentials, so it harms only that operator; multi-statements additionally require the operator to opt in.
  • Does a MATERIALIZED CTE hide a data-modifying statement from read-only mode?
    The CTE parsing is pre-existing code the PR does not touch, and the DML runs inside a session that read-only mode never commits, so the effects are rolled back.
  • Can a SQL comment substitute for the whitespace between `INTO` and `OUTFILE`/`DUMPFILE` to slip past both patterns?
    No statement form was found where a comment separator yields a valid file-writing statement that avoids both the raw `INTO OUTFILE`/`DUMPFILE` match and the plain `INTO` match.
Review history (2)
  • Review 2 · 55aea41 · Nov 23 14:06 UTC · Nothing new
  • Review 1 · 9be4ef5 · Nov 23 07:19 UTC · Found 1 Medium Vulnerability

Review 2 on this PR · 55aea41 · requested Nov 23 13:55 UTC by @Vidit-Ostwal


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@linear

linear Bot commented Nov 23, 2026

Copy link
Copy Markdown

OSS-262

@strix-security strix-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Strix flagged a new security finding below. See the pinned summary comment for the full PR status.

Read-only mode only checked the leading keyword, so SELECT ... INTO
OUTFILE/DUMPFILE could write files on the database host and
SELECT ... INTO <table> could create tables. Reject INTO clauses
(outside string literals) for read commands and CTEs when allow_dml=False.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Vidit-Ostwal
Vidit Ostwal (Vidit-Ostwal) force-pushed the viditostwal/oss-262-medium-nl2sqltool-read-only-mode-allows branch from 79ea45e to eb44383 Compare November 23, 2026 13:50
…sing

Match INTO OUTFILE/DUMPFILE on the raw statement, and scan raw text for
INTO when the statement contains backslashes, double quotes or backticks,
since the single-quote blanker can disagree with the database lexer there.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant