Merge security review fixes: sandbox refuses async/stackalloc/MethodImpl, unwinding-overflow guard, deep-data types (#971); T-SQL ScriptDom single-SELECT guard (#974); Auth 0.5.0 directory re-query on revalidation (#975); fleet-diagnostics target check (#973)

This commit is contained in:
Joseph Doherty
2026-12-03 12:27:35 -05:00
25 changed files with 1299 additions and 71 deletions
+18 -4
View File
@@ -214,6 +214,18 @@ row:
carriage return. T-SQL's `]]` inside `[ … ]` and MySQL's `#` comments are modelled. An **Odbc** driver's
backend is unknown, so its statement must lex identically under every dialect (so must a statement checked
without a provider). Changing the driver form's **Provider** re-validates the queries.
- **On SQL Server the statement is also parsed (2026-12-02 review).** `;` is not a statement boundary in
T-SQL — `SELECT 1 COMMIT KILL 55` is three statements to SQL Server and was one `SELECT` to the lexer, so
a `COMMIT` ending the rolled-back transaction followed by `DISABLE TRIGGER ALL ON DATABASE`, `KILL`,
`SHUTDOWN WITH NOWAIT` or `WRITETEXT` passed the guard. For **SqlServer** — and for **Odbc** and no
provider, whose backend may be SQL Server, so the strictest reading applies — the statement is parsed
with `Microsoft.SqlServer.TransactSql.ScriptDom` and must be exactly **one batch holding exactly one
`SELECT`**, with no `INTO` and no `OPENQUERY` / `OPENROWSET` / `OPENDATASOURCE` (they run text on another
server or read a file). CTEs, subqueries, window functions, `UNION`, `OPTION (…)` and `@name` parameters
are ordinary `SELECT`s and pass. An Odbc statement's positional `?` markers are read as variables for the
parse; anything else SQL Server's grammar does not accept — a PostgreSQL `::` cast, `LIMIT`, a T-SQL
reserved word used as a bare alias (`AS top`) — is refused on Odbc, so quote or rename it. The lexical
rules remain as a second, independent layer.
- **It executes in a read-only transaction where the provider has one** — always rolled back regardless:
PostgreSQL and Oracle `SET TRANSACTION READ ONLY`, MySQL a read-only **session** plus `START TRANSACTION
READ ONLY` (a smuggled `COMMIT` ends a transaction, not a session; the session is restored afterwards). A
@@ -223,8 +235,8 @@ row:
positional `$n` parameters (rewritten from your `@name` markers), which makes Npgsql pass the text unsplit
as one extended-protocol statement; the server rejects anything after a `;` itself. Oracle (ODP.NET)
refuses a second statement anyway. SQL Server and MySQL execute a multi-statement batch — there the
per-dialect guard is the line, and MySQL's read-only session is defence in depth that hidden text could
undo.
guard is the line (on SQL Server its T-SQL parse, above), and MySQL's read-only session is defence in depth
that hidden text could undo.
- None of this replaces the grant: a non-transactional side effect (an e-mail procedure, a call out to
another system, an autonomous transaction) is outside every layer — which is why a read-only driver
**must** connect with a `SELECT`-only login (see [Database login](#database-login-required)).
@@ -484,7 +496,9 @@ value. Writes never change driver health. Discovery advertises `Operate` only fo
two rows per changed row (#987). `NamedQueryBypassLiveTests` proves, per provider, that each smuggled-write
string is a working bypass the old way, that the guard refuses it, and that with the guard bypassed the
write still does not land (PostgreSQL, MySQL) — plus the MySQL session restore and an Oracle read under
`SET TRANSACTION READ ONLY`.
`SET TRANSACTION READ ONLY`. `SqlServerNamedQueryBatchLiveTests` does the same for SQL Server's `;`-less
batch (`SELECT 1 AS v COMMIT UPDATE …` commits the old way; the guard refuses it for SqlServer and Odbc) and
reads a CTE + window-function + subquery + parameter query Good through the driver.
## Database login (required)
@@ -494,7 +508,7 @@ The driver's own guards are not a substitute for the database's grants:
the tables and views its tags and named queries read, and nothing else. The named-query guard is a
per-dialect keyword check plus an always-rolled-back (read-only where the provider has one) transaction;
none of that can stop a **non-transactional** side effect — a function that sends mail or calls out,
autonomous transactions — and on SQL Server and MySQL a statement that got past the lexer would run as a
autonomous transactions — and on SQL Server and MySQL a statement that got past the guard would run as a
batch. Only the grant is a boundary.
- **A writable driver must connect with a login limited to its write targets** — `SELECT` as above,
plus exactly what its modes need on exactly the tables / procedures its writable tags name: