Skip to content

Validate dataset primary key identifiers#4

Open
bob-codedaptive wants to merge 1 commit into
mainfrom
codex/fix-sql-injection-in-primary-key-column
Open

Validate dataset primary key identifiers#4
bob-codedaptive wants to merge 1 commit into
mainfrom
codex/fix-sql-injection-in-primary-key-column

Conversation

@bob-codedaptive

Copy link
Copy Markdown
Member

Motivation

  • The dataset schema field for a declared primary key (primaryKeyColumn / primary_key_column) was a raw string interpolated into backend CREATE TABLE DDL without being validated, enabling SQL identifier quote-breakout and statement injection.
  • The existing identifier validator validateDatasetColumnIdentifier / validate_dataset_column_identifier was already applied to columns and indexes but the primary-key field was omitted across Swift and Rust stores, leaving a high-impact SQL injection surface.

Description

  • Apply the existing identifier validation to DatasetSchema.primaryKeyColumn / primary_key_column before any backend/state access in Swift stores: PersistenceKitSQLite/SQLiteDatasetStore.swift, PersistenceKitPostgreSQL/PostgreSQLDatasetStore.swift, and PersistenceKitInMemory/InMemoryDatasetStore.swift.
  • Apply the same validation in Rust stores: rust/src/sqlite.rs, rust/src/postgres.rs, and rust/src/dataset_store.rs (InMemory), so the PK name is checked prior to constructing/issuing DDL.
  • Add regression tests that assert a double-quote / quote-breaking payload in the declared primary-key name is rejected for the Swift dataset store tests and the Rust SQLite dataset-store tests (DatasetStoreTests.swift and rust/src/sqlite.rs).

Testing

  • Ran the focused Rust test cargo test create_dataset_rejects_primary_key_column_with_double_quote and the new Rust unit passed (ok).
  • Attempted the Swift test swift test --filter DatasetStoreTests/invalidIdentifier_primaryKeyColumn_sqlInjection_doubleQuote but the run was blocked/failed due to a missing local package dependency (packages/libs/SubstrateTypes), so Swift-side tests could not be executed in this environment.
  • Verified repository changes compile and unit-test-suite execution for the Rust crate completed with the new test included (no regressions observed for the exercised checks).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant