Repository navigation
sqlx 0.9.1: audit and mark every dynamic SQL string - #177
Merged
Merged
Conversation
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>
This was referenced Dec 3, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #173, which fails to compile (26 errors).
What changed in sqlx 0.9
query(),query_as(),query_scalar()andExecutor::execute()now takeimpl SqlSafeStr, implemented only for&'static str. Any string built at runtime must be wrapped inAssertSqlSafe(..), which asserts it was checked for injection.Audit — no user input reaches SQL text
Every dynamic site (24) builds its SQL from one of:
MODEL_COLUMNS,MODEL_COLUMNS_PREFIXED,CHANNEL_COLUMNS,CODEPLUG_SUMMARY_SQL,STALE_WHERE, the dashboard filter fragments.?Nplaceholders with values bound — the DMR user search, andpriority_case_sql, which emitsWHEN ? THEN iand binds the country names.""-quoted — backup row counts and the restore table replace.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_itemsnow takesimpl SqlSafeStrso its literal callers stay unwrapped. The two lifetime errors (backup.rsrun_script,dashboard.rs) go away by passing owned strings.Verified
npm run cigreen — 1089 tests, clippy-D warnings. Includes the backup/restore tests (VACUUM INTO, ATTACH, table replace, data fixups).migrate!().run()checks every applied migration's checksum, so 0.9 accepts 0.8-era databases.🤖 Generated with Claude Code