rust: Add config-derived table name barrier for SQL injection#374
Open
chanel-y wants to merge 2 commits into
Open
rust: Add config-derived table name barrier for SQL injection#374chanel-y wants to merge 2 commits into
chanel-y wants to merge 2 commits into
Conversation
Adds a barrier that blocks taint propagation through struct field accesses whose names match table/collection/schema/index patterns (e.g., self.events_table, self.view_table). These fields are typically initialized at service startup from configuration, not from per-request user data. This addresses 3 of 4 false positives observed in triage where internal aggregate table name fields were incorrectly flagged as SQL injection sinks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Description
This PR adds a ConfigDerivedTableNameBarrier to the Rust SQL-injection query. It treats reads of struct fields whose names denote a database identifier — matching (?i).*(table|collection|schema|bucket|index|view)(_name)?$ — as taint barriers. These fields are, by convention, populated at service startup from hardcoded strings or configuration rather than from per-request user input, so interpolating them into a query string is not user-controlled SQL injection.
False positives eliminated
All three alerts come from the same delete_aggregate method in Nexus.Foundation/crates/nexus-persistence/src/es/store.rs . In each case the only value interpolated into the SQL text is an internal table-identifier field ( self.events_table , self.snapshots_table , self.view_table ), while the sole request-derived value ( aggregate_id ) is safely parameterized with .bind(...) / $1 .
The table-identifier fields are initialized once from the aggregate type name (a compile-time/config constant), never from request data:
// AggregateTableConfig::new(aggregate_name) — service setup, not request data
Self {
events_table: format!("{}_events", aggregate_name),
snapshots_table: format!("{}_snapshots", aggregate_name),
view_table: format!("{}_view", aggregate_name),
}
1. store.rs:74 — events_table
Alert: https://codeql.microsoft.com/issues/85f36f3f-1401-45a7-a1d6-ea277c2f4933?Campaign=5272e251cdc44e9eaa056e5b1c1a1c06
if let Err(e) = sqlx::query(&format!(
"DELETE FROM {} WHERE aggregate_id = $1",
self.events_table // internal identifier — the only {} filler
))
.bind(aggregate_id) // request value — parameterized as $1
.execute(pool)
.await
2. store.rs:91 — snapshots_table
Alert: https://codeql.microsoft.com/issues/a3e7f634-5aee-4bfc-b242-d7cd453021be?Campaign=5272e251cdc44e9eaa056e5b1c1a1c06
if let Err(e) = sqlx::query(&format!(
"DELETE FROM {} WHERE aggregate_id = $1",
self.snapshots_table // internal identifier — the only {} filler
))
.bind(aggregate_id) // request value — parameterized as $1
.execute(pool)
.await
3. store.rs:108 — view_table
Alert: https://codeql.microsoft.com/issues/cd77a610-9abb-4125-b138-51d04b4fd1a9?Campaign=5272e251cdc44e9eaa056e5b1c1a1c06
let result = sqlx::query(&format!(
"DELETE FROM {} WHERE view_id = $1",
self.view_table // internal identifier — the only {} filler
))
.bind(aggregate_id) // request value — parameterized as $1
.execute(pool)
.await?;
Why this fixes the false positives
CodeQL reports these because its taint tracking follows values into the format! → sqlx::query sink. But the only value spliced into the SQL structure is a table identifier read from an internal struct field ( self.events_table etc.), which is a FieldExpr whose identifier ends in table / view . The new ConfigDerivedTableNameBarrier marks such field reads as barriers, so the config-derived identifier no longer taints the query. The request-controlled aggregate_id is unaffected — it is already safe because it is bound as $1 rather than concatenated.