You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat(nl2sql): prompt-injection boundary defence with refusal sentinel
Defence-in-depth at the prompt layer for translate_nl_to_sql (the AST
allowlist stays the enforcement backstop):
- Wrap the user question in <user_request>...</user_request> delimiters.
- System prompt instructs the model to treat that text as data (never
instructions) and to REFUSE any out-of-scope request (write/DDL,
secrets, 'ignore previous instructions', ...) by emitting the sentinel
'-- MCPG_REFUSED: <reason>'.
- translate detects the sentinel (JSON sql field or bare reply) and
returns TranslationResult(refused=True, refusal_reason=...) with empty
sql, never forwarding it to SafeSqlDriver / execution.
Adds refused / refusal_reason to the result (return-shape snapshot
regenerated; tool input surface unchanged). 3 new unit tests cover the
delimiter wrap, the JSON-field sentinel, and the bare-line sentinel.
This is the first of the two remaining security-hardening.md items; the
EXPLAIN dry-run pre-flight is a fast-follow on this branch.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0122yLZLJ8t4W43sdN6BmTZc
* feat(nl2sql): EXPLAIN dry-run pre-flight for translate_nl_to_sql
Second of the two remaining security-hardening.md items. Before returning
or executing the generated SQL, run a non-executing EXPLAIN (reusing
mcpg.query.explain_query, so it's SafeSqlDriver-validated) to catch queries
that pass the structural allowlist but reference a non-existent
column/table or mistype something:
- Planner rejection -> structured error='query invalid: <message>' with the
SQL returned for inspection; nothing executed.
- Pre-flight statement_timeout -> degrade to 'skip, proceed' (don't block a
valid translation).
- New explain_preflight tool arg (default on); bypassable per call.
Surface snapshot regenerated (translate_nl_to_sql gains explain_preflight).
2 new unit tests (invalid-query surfaced; bypass when disabled) + an EXPLAIN
route in the nl2sql test schema so the default-on pre-flight passes.
Completes security-hardening.md — both NL->SQL items now shipped.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0122yLZLJ8t4W43sdN6BmTZc
---------
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments