Skip to content

Commit

Permalink
Bug fix: Enhanced SQL statement validation with word boundary matching (
Browse files Browse the repository at this point in the history
#2324)

Co-authored-by: AbdulRehman Faraj <[email protected]>
  • Loading branch information
nitin-singla and AbdulRehman Faraj authored Jan 14, 2025
1 parent 4eea8e2 commit 36a6ee0
Showing 1 changed file with 0 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
import com.amazonaws.athena.connector.lambda.metadata.optimizations.querypassthrough.QueryPassthroughSignature;
import com.google.common.collect.ImmutableSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.glue.model.ErrorDetails;
Expand All @@ -31,7 +30,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

public class DDBQueryPassthrough implements QueryPassthroughSignature
{
Expand Down Expand Up @@ -82,15 +80,5 @@ public void customConnectorVerifications(Map<String, String> engineQptArguments)
if (!upperCaseStatement.startsWith("SELECT")) {
throw new AthenaConnectorException("Statement does not start with SELECT.", ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).build());
}

// List of disallowed keywords
Set<String> disallowedKeywords = ImmutableSet.of("INSERT", "UPDATE", "DELETE", "CREATE", "DROP", "ALTER");

// Check if the statement contains any disallowed keywords
for (String keyword : disallowedKeywords) {
if (upperCaseStatement.contains(keyword)) {
throw new AthenaConnectorException("Unaccepted operation; only SELECT statements are allowed. Found: " + keyword, ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).build());
}
}
}
}

0 comments on commit 36a6ee0

Please sign in to comment.