security: validate keyspace and datacenter names to prevent CQL injection (GHSA-p64p-96pw-mxwv)#2472
Merged
Merged
Conversation
…tion (GHSA-p64p-96pw-mxwv)
Two unrelated CQL injection sinks shared a common root cause:
user-supplied identifiers were interpolated into CQL via String.format
without validation or escaping.
1. dropKeyspace / dropNamespace passed the request `name` directly into
`DROP KEYSPACE IF EXISTS "%s"`. The analogous Create resolvers already
apply `NamingRules.KEYSPACE.checkRule(name)`; this commit applies the
same validation in both Drop resolvers, mirroring the Create path.
2. NetworkTopologyStrategy replication-map construction in
CreateNamespaceKeyspaceCommandResolver interpolated user-supplied
datacenter-name keys via `", '%s': %d"` with no validation. A crafted
key could break out of the single-quoted CQL literal and inject
additional CQL into the `WITH REPLICATION = {...}` clause of
`CREATE KEYSPACE`. This commit adds an allowlist validation
(`[A-Za-z0-9_-]+`, max 48 chars) that accepts realistic cloud DC names
(e.g. `us-east-1`) while rejecting any character that could break the
literal.
Adds a new `UNSUPPORTED_REPLICATION_DATA_CENTER_NAME` SchemaException
code with a corresponding template in `errors.yaml`, and unit tests for
both the drop-validation and DC-name-validation paths.
Contributor
📈 Unit Test Coverage Delta vs Main Branch
|
Contributor
Unit Test Coverage Report
|
Contributor
📈 Integration Test Coverage Delta vs Main Branch (dse69-it)
|
Contributor
Integration Test Coverage Report (dse69-it)
|
Contributor
📈 Integration Test Coverage Delta vs Main Branch (hcd-it)
|
Contributor
Integration Test Coverage Report (hcd-it)
|
3 tasks
erichare
added a commit
that referenced
this pull request
May 19, 2026
…up to #2472) PR #2472 closed the GHSA-p64p-96pw-mxwv injection vectors with input validation. This follow-up addresses the root cause for the keyspace-name sinks: replace the String.format CQL interpolation in CreateKeyspaceOperation and DropKeyspaceOperation with the driver's SchemaBuilder using CqlIdentifier.fromInternal(name). CqlIdentifier doubles embedded quote characters, so the keyspace identifier is well-formed regardless of upstream validation. Driver-gap finding for datacenter names: SchemaBuilder.withNetworkTopologyStrategy(Map) does NOT escape map keys (see OptionsUtils.extractOptionValue in java-driver-query-builder 4.19.0-preview1 — a hostile DC name with a single quote produces broken CQL). The DC-name allowlist applied by the resolver is therefore the actual security control for the replication map, not just defense-in-depth. The resolver comment is updated to flag this so the allowlist is not removed in a later cleanup. Changes: - CreateKeyspaceOperation: take (name, strategy, strategyOptions) and build the SimpleStatement via SchemaBuilder.createKeyspace(CqlIdentifier). - DropKeyspaceOperation: build via SchemaBuilder.dropKeyspace(CqlIdentifier). - CreateNamespaceKeyspaceCommandResolver: drop the dead getReplicationMap string-building; keep DC-name validation (now wired via validateStrategyOptions). Updated comment documents the driver-gap rationale. - New operation-level tests pin the SchemaBuilder behaviour: identifier escaping for keyspace names, fallback to SimpleStrategy, hyphenated DC name support, and a regression-pinning test that documents the driver's unescaped-map-key behaviour. - Existing resolver tests adjusted to the new record fields and existing injection-rejection tests retained.
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.
Fix for GHSA-p64p-96pw-mxwv.
Summary
Two unrelated CQL-injection sinks share a common root cause: user-supplied identifiers are interpolated into CQL via
String.formatwithout validation or escaping.dropKeyspace/dropNamespace— the requestnameis passed directly intoDROP KEYSPACE IF EXISTS "%s". The analogous Create resolvers already validate viaNamingRules.KEYSPACE.checkRule(name); the Drop resolvers do not. A double-quote character breaks out of the quoted identifier.CreateNamespaceKeyspaceCommandResolver.networkTopologyStrategyMapinterpolates user-supplied datacenter-name keys via", '%s': %d"with no validation. A single-quote in the key breaks out of the literal and lets an attacker inject CQL into theWITH REPLICATION = {…}clause.Changes
DropKeyspaceCommandResolver,DropNamespaceCommandResolver— applyNamingRules.KEYSPACE.checkRule(name), mirroring the Create path.CreateNamespaceKeyspaceCommandResolver— validate each NetworkTopologyStrategy datacenter-name key against an allowlist ([A-Za-z0-9_-]+, max 48 chars). The character set accepts realistic cloud DC names likeus-east-1while rejecting any character that could break the single-quoted CQL literal (notably',\, whitespace).SchemaException.Code.UNSUPPORTED_REPLICATION_DATA_CENTER_NAMEwith template inerrors.yaml.Integerreplication-factor values are unaffected — Jackson type-coercion rejects non-numeric input and%donly formats numerics.Test plan
DropKeyspaceCommandResolverTest:dropNamespacealiasCreateKeyspaceCommandResolverTest:us-east-1) — regression guard for legitimate users./mvnw test -Dtest='DropKeyspaceCommandResolverTest,CreateKeyspaceCommandResolverTest'— 21 / 21 pass.createKeyspace+dropKeyspacehappy path against a real cluster.vulnerable_version_rangeon the advisory before publishing the GHSA (currently<= 1.0.xas a placeholder; currentpom.xmlis1.0.47-SNAPSHOT).Notes for reviewers
-so Astra / AWS-region style DC names (dc-westus2,us-east-1) keep working. If you'd prefer the stricter\w+rule used for keyspace identifiers, flag it and I can tighten.DropKeyspaceOperation.DROP_KEYSPACE_CQLitself; the validated identifier is still interpolated. The fix relies on the allowlist being CQL-safe. Switching to aQueryBuilderAPI or driver-sideCqlIdentifierquoting would be a larger refactor and is out of scope for this patch.