diff --git a/document-store/src/main/java/org/hypertrace/core/documentstore/expression/impl/JsonIdentifierExpression.java b/document-store/src/main/java/org/hypertrace/core/documentstore/expression/impl/JsonIdentifierExpression.java index 6d3abf4f..277af0f2 100644 --- a/document-store/src/main/java/org/hypertrace/core/documentstore/expression/impl/JsonIdentifierExpression.java +++ b/document-store/src/main/java/org/hypertrace/core/documentstore/expression/impl/JsonIdentifierExpression.java @@ -29,19 +29,14 @@ public static JsonIdentifierExpression of(final String columnName, final String. } public static JsonIdentifierExpression of(final String columnName, final List jsonPath) { - // Validate column name to prevent SQL injection BasicPostgresSecurityValidator.getDefault().validateIdentifier(columnName); - // Validate each element in the JSON path if (jsonPath == null || jsonPath.isEmpty()) { throw new IllegalArgumentException("JSON path cannot be null or empty"); } - // Validate JSON path to prevent SQL injection BasicPostgresSecurityValidator.getDefault().validateJsonPath(jsonPath); - // Create unmodifiable defensive copy using List.copyOf (Java 10+) - // If already unmodifiable, returns the same instance List unmodifiablePath = List.copyOf(jsonPath); // Construct full name for compatibility: "customAttr.myAttribute" diff --git a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/query/v1/transformer/FlatPostgresFieldTransformer.java b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/query/v1/transformer/FlatPostgresFieldTransformer.java index 6ff6f790..65e84faf 100644 --- a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/query/v1/transformer/FlatPostgresFieldTransformer.java +++ b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/query/v1/transformer/FlatPostgresFieldTransformer.java @@ -32,7 +32,6 @@ public FieldToPgColumn transform( public FieldToPgColumn visit(IdentifierExpression expression) { String fieldName = expression.getName(); - // Validate identifier to prevent SQL injection (defense in depth) BasicPostgresSecurityValidator.getDefault().validateIdentifier(fieldName); // Check if this field has been unnested (e.g., "tags" -> "tags_unnested") @@ -50,9 +49,7 @@ public FieldToPgColumn visit(IdentifierExpression expression) { */ @Override public FieldToPgColumn visit(JsonIdentifierExpression expression) { - // Validate column name and JSON path to prevent SQL injection (defense in depth) - // This is redundant with validation in JsonIdentifierExpression.of(), but provides - // an additional security layer in case the expression is constructed through other means + BasicPostgresSecurityValidator.getDefault().validateIdentifier(expression.getColumnName()); BasicPostgresSecurityValidator.getDefault().validateJsonPath(expression.getJsonPath()); diff --git a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/utils/BasicPostgresSecurityValidator.java b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/utils/BasicPostgresSecurityValidator.java index d231cf93..e126bf98 100644 --- a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/utils/BasicPostgresSecurityValidator.java +++ b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/utils/BasicPostgresSecurityValidator.java @@ -14,21 +14,25 @@ public class BasicPostgresSecurityValidator implements PostgresSecurityValidator /** * Default pattern for PostgreSQL column/table identifiers. * - *

Pattern: {@code ^[a-zA-Z_][a-zA-Z0-9_]*$} + *

Pattern: {@code ^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z_][a-zA-Z0-9_]*)*$} * *

Allowed: * *

* *

Not allowed: * *