Skip to content

sqlx 0.9.1: audit and mark every dynamic SQL string - #177

Merged
ww8l merged 1 commit into
mainfrom
deps-sqlx-0.9
Dec 3, 2026
Merged

ww8l merged 1 commit into
mainfrom
deps-sqlx-0.9

Conversation

@ww8l

@ww8l ww8l commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Supersedes #173, which fails to compile (26 errors).

What changed in sqlx 0.9

query(), query_as(), query_scalar() and Executor::execute() now take impl SqlSafeStr, implemented only for &'static str. Any string built at runtime must be wrapped in AssertSqlSafe(..), which asserts it was checked for injection.

Audit — no user input reaches SQL text

Every dynamic site (24) builds its SQL from one of:

  • Constants — MODEL_COLUMNS, MODEL_COLUMNS_PREFIXED, CHANNEL_COLUMNS, CODEPLUG_SUMMARY_SQL, STALE_WHERE, the dashboard filter fragments.
  • Numbered ?N placeholders with values bound — the DMR user search, and priority_case_sql, which emits WHEN ? THEN i and binds the country names.
  • Table/column names from the database's own schema, ""-quoted — backup row counts and the restore table replace.
  • A file path in VACUUM INTO / ATTACH DATABASE, with ' doubled. SQLite has no backslash escapes, so this is complete.

Each site is wrapped, with a comment where the reason isn't obvious from the line. dashboard::warning_items now takes impl SqlSafeStr so its literal callers stay unwrapped. The two lifetime errors (backup.rs run_script, dashboard.rs) go away by passing owned strings.

Verified

  • macOS: npm run ci green — 1089 tests, clippy -D warnings. Includes the backup/restore tests (VACUUM INTO, ATTACH, table replace, data fixups).
  • Existing database: the dev app opened a dev DB with 21 migrations applied under sqlx 0.8, and started cleanly — migrate!().run() checks every applied migration's checksum, so 0.9 accepts 0.8-era databases.
  • Not verified: a backup → restore round trip through the UI; Linux and Windows (this PR's CI).

🤖 Generated with Claude Code

sqlx 0.9 accepts only &'static str as query text; anything built at
runtime must be wrapped in AssertSqlSafe after checking it carries no
injectable input. 24 sites did, plus two lifetime errors from the same
change. Supersedes Dependabot #173.

Audit: no user input reaches SQL text anywhere. Each dynamic piece is a
const fragment (MODEL_COLUMNS, CHANNEL_COLUMNS, STALE_WHERE, dashboard
filters), numbered ?N placeholders with values bound (DMR user search,
priority-country CASE), table/column names read from the schema and
""-quoted (backup counts, restore), or a file path in VACUUM INTO / ATTACH
with ' doubled, which is complete escaping for an SQLite string literal.

dashboard::warning_items now takes impl SqlSafeStr, so its literal callers
stay unwrapped. run_script passes an owned string, which also clears the
lifetime error there.

Verified on macOS: npm run ci green (1089 tests, including backup/restore),
and the dev app opened an existing dev DB with 21 migrations applied under
0.8 without a checksum mismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ww8l
ww8l merged commit 9557cf0 into main Dec 3, 2026
3 checks passed
@ww8l
ww8l deleted the deps-sqlx-0.9 branch December 3, 2026 14:47
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