Repository navigation
feat(sqlite): [SQL Sanitizing 3] Sanitize SQL span descriptions in the Android SQLite integration - #6802
feat(sqlite): [SQL Sanitizing 3] Sanitize SQL span descriptions in the Android SQLite integration#6802lbloder wants to merge 3 commits into
Conversation
PR risk: mediumFor commit Main concerns: data sent to Sentry, reach, dependencies customers inherit. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
|
On-device timing with and without sanitizationPer call, in microseconds (µs). Measured on
Over all 14 short Room-style statements of the harness, sanitization adds +11 to +35 µs (OpenHelper) and +8 to +30 µs (driver); the analyzer alone takes 5.4–21.6 µs on 75 typical statements (median 10.6–11.9 µs). Device: ASUS Zenfone 10 ( How often: 2 runs of 3 rounds each. Per round and statement: 2,000 measured calls per variant after 200 warm-up calls; analyzer alone: 10,000 calls after 2,000 warm-up. Each call is timed on its own with Setup:
Reading:
|
📲 Install BuildsAndroid
|
PR Stack (SQL Sanitizing)
📜 Description
Wires the SQL query analyzer from #6795 into
sentry-android-sqlite, for both theSupportSQLiteOpenHelperintegration (OpenHelperSpans) and theSQLiteDriverintegration (DriverSpans).db.query.text,db.query.summaryanddb.stored_procedure.namewhen present, anddb.system.name(sqlite, also for in-memory databases) anddb.namespacenext to the existingdb.systemanddb.name. If the analysis fails, the span keeps no query text at all, never the raw statement.OpenHelperSpansnow ends the span at the time the database call returned or threw, asDriverSpansalready did. Before, the span ended after the post-processing, so the analysis (and on the main thread the call-stack walk) would have counted as query time.dbMetadataFromFileNamecuts the name passed toSQLiteDriver.openat the first?or#, so URI parameters such as an encryption key can't end up indb.name/db.namespacewhen a driver that opens URI filenames is wrapped. The defaultBundledSQLiteDriver.open(String)doesn't open URIs.💡 Motivation and Context
SQLite spans carry the raw SQL statement today, including literal values from statements that don't use bind parameters.
💚 How did you test it?
./gradlew :sentry-android-sqlite:check: 112 tests, 0 failures. As in feat(jdbc): [SQL Sanitizing 2] Sanitize SQL span descriptions in the JDBC integration #6798, the tests check wiring only: span fields equalSqlQueryAnalyzer's output forsqlite, so a grammar sync never needs re-baselining. Per integration: sanitized description and query keys (OpenHelper on the success and the error path), the 8 KiB limit (checked to differ from the output at 32 KiB), analysis failure, no analysis without a parent or with a no-op parent, the new keys. The OpenHelper span end is tested with a fake clock that advances during the database call and during the analysis. Each new test was checked against a mutation (raw SQL as description or fallback, noapplyTo, no no-op check, limit 32 KiB, end time read after the analysis, parameters cut at?only, …).db.sql.queryspans have sanitized descriptions and the new keys, e.g.INSERT OR ABORT INTO `song` (`id`,`title`,`artist`) VALUES (nullif(?, ?),?,?)with summaryINSERT `song`; text and summary match the analyzer's JVM output for the same statements.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
ignoredSpanOriginscontainingauto.db.sqlitemost likely has no effect today (pre-existing, found by reading):SentryTracer.createChildchecks the origin passed inSpanOptions, and both integrations set it only afterstartChild. Fix: pass the origin atstartChildand skip the analysis for ignored origins, asSentryJdbcEventListenerdoes.#skip-changelog