Skip to content

feat: make the raw SQL slots impossible to whitelist - #475

Merged
polterguy merged 1 commit into
masterfrom
feat/raw-sql-not-whitelistable
Dec 5, 2026
Merged

polterguy merged 1 commit into
masterfrom
feat/raw-sql-not-whitelistable

Conversation

@polterguy

Copy link
Copy Markdown
Owner

Closes the second case in the appendix of the external security review of 1 December.

The problem

Pinning data.connect:chinook in a [whitelist] only chooses which database the connection opens. Raw SQL text reaches any other database the login can:

  • SQLite: ATTACH 'files/data/magic.db', which the researcher used to read the users table, insert a root user and log in as root
  • MySQL / SQL Server: cross-database names (magic.users, magic.dbo.users)
  • PostgreSQL: pg_read_file, COPY ... FROM PROGRAM, dblink

Policing arbitrary SQL across four dialects from the application side is a blacklist that can't be won. The only real boundary for raw SQL is database-level permissions, which a pin doesn't provide.

The change

  • select, scalar and execute for data.*, sqlite.*, mysql.*, pgsql.* and mssql.* (15 slots) now declare Whitelistable = false. A [whitelist] naming any of them is refused when it's declared, the same as the tasks.*, io.file.save and git.* slots.
  • data.* is included as well as the dialect slots, so neither layer is left open.
  • Sandboxes keep full CRUD through data.read, data.create, data.update and data.delete, which build their own SQL.
  • Trusted code (granted files, dynamic slots, normal endpoints) is unaffected, since it runs outside the whitelist.
  • WhitelistableTests.NeverWhitelistable lists the 15 names, and its comment explains why.

Breaking for sandboxes that grant raw SQL

A [whitelist] that lists any of these slots now throws [data.select] can never be used inside a [whitelist]. Known places:

  • Generator eval tests 282-sandbox-allow-one-database.hl and 292-sandbox-pinned-database.hl grant data.select / sqlite.scalar, so both will now fail. They're left unchanged here, for the eval owner to decide.
  • Fine-tune corpus: about 337 snippets whitelist raw SQL. Left unchanged; the generator will keep emitting the pattern until the corpus is updated.
  • Live sandbox policies (hl-test demo, NL API, playground) need checking before deploying.

Not built or tested locally; CI runs the analyzer build and the tests.

Bumps the version to v24.5.4.

🤖 Generated with Claude Code

A pinned [data.connect] only chooses the database a connection opens.
Raw SQL text reaches every other database the login can - ATTACH in
SQLite, cross-database names in MySQL and SQL Server, server functions
in PostgreSQL - so a sandbox granted [data.select] next to a pinned
connection could read and write Magic's own database and create a root
user. That cannot be confined from the application side.

[select], [scalar] and [execute] for [data] and all four dialects now
declare Whitelistable = false, so a [whitelist] naming any of them is
refused when it is declared. Sandboxes use [data.read], [data.create],
[data.update] and [data.delete], which build their own SQL.

Bumps the version to v24.5.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
polterguy added a commit to polterguy/hyperlambda-generator-eval that referenced this pull request Dec 5, 2026
Magic no longer lets a [whitelist] grant the raw SQL slots, since a
pinned connection does not confine SQL text (polterguy/magic#475).
Both reference solutions granted them, so they now grant the read slot
instead, and their cases use a read in place of SQL text.

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

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@polterguy
polterguy merged commit 4cabbe3 into master Dec 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant