Skip to content

fix(security): parameterize readByUUID to close CQL injection (H1) - #146

Open
pallakartheekreddy wants to merge 1 commit into
masterfrom
security/fix-cql-injection-readbyuuid
Open

fix(security): parameterize readByUUID to close CQL injection (H1)#146
pallakartheekreddy wants to merge 1 commit into
masterfrom
security/fix-cql-injection-readbyuuid

Conversation

@pallakartheekreddy

Copy link
Copy Markdown
Collaborator

Summary

Closes the CQL injection (H1, P0) in implementation-designs/sunbird-dial-service.md.

The vulnerability

CassandraStore.readByUUID built CQL by raw string concatenation:

String selectQuery = "select * from " + keyspace+"."+table + " where " + key + "=" + value + ";";

Its only caller, QRCodesStore.read, passed the un-sanitized :processid path param from GET /dialcode/v4/batch/read/:processid straight into value, so a crafted processid injected CQL.

The fix

  • readByUUID now builds the query with QueryBuilder.eq(key, value) — the value is bound through its TypeCodec instead of concatenated (mirrors the sibling read() already in this class). Signature tightened to java.util.UUID (processid is a uuid column; single caller).
  • QRCodesStore.read parses the path param via UUID.fromString before the DB call, so any malformed id — including an injection payload like x' OR 1=1-- — is rejected up front.

key is a compile-time enum name (DialCodeEnum.processid.name()), never user input.

Backward compatibility

Response for valid UUIDs is unchanged. Malformed input still surfaces as ERR_QRCODES_BATCH_INFO (not-found) via the existing catch, preserving current client behaviour. No DB/schema change.

Verification

  • mvn test-compile under JDK 11 — exit 0; both CassandraStore and QRCodesStore recompiled.

Note: two pre-existing tracked deletions under build/ in the working tree are unrelated and excluded from this branch.

CassandraStore.readByUUID built CQL by raw string concatenation:
  "select * from " + keyspace+"."+table + " where " + key + "=" + value + ";"
Its only caller, QRCodesStore.read, passed the un-sanitized :processid path param
from GET /dialcode/v4/batch/read/:processid straight in, so a crafted processid
injected CQL.

- readByUUID now builds the query with QueryBuilder.eq(key, value) so the value is
  bound through its TypeCodec instead of concatenated (mirrors the sibling read()).
  Signature tightened to java.util.UUID (processid is a uuid column; single caller).
- QRCodesStore.read parses the path param via UUID.fromString before the DB call, so
  any malformed id (including injection payloads) is rejected up front.

Response for valid UUIDs is unchanged; malformed input still surfaces as
ERR_QRCODES_BATCH_INFO (not-found), preserving existing client behaviour. No schema change.

Verified: dial-service test-compile under JDK 11 (both classes recompiled, exit 0).
Implements H1 (P0) from implementation-designs/sunbird-dial-service.md.
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant