Skip to content

Commit

Permalink
Added javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecsilva committed Aug 1, 2024
1 parent ceb3e74 commit 3102d01
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import com.github.javaparser.ast.expr.MethodCallExpr;

/** Composes several transformations related to SQL injections. */
public final class SQLInjectionFixComposer {

private SQLInjectionFixComposer() {}

/**
* Given a {@link MethodCallExpr} related to executing JDBC API SQL queries (i.e.
* prepareStatement(), executeQuery(), etc.), parameterize data injections or add a validation
* step for structural injections.
*/
public static boolean checkAndFix(final MethodCallExpr methodCallExpr) {
// Check if any data injection fixes apply
// First, check if any data injection fixes apply
var maybeFixed = new SQLParameterizer(methodCallExpr).checkAndFix();
if (maybeFixed.isPresent()) {
// If yes, execute cleanup steps and check if any table injection remains.
SQLParameterizerWithCleanup.cleanup(maybeFixed.get());
SQLTableInjectionFilterTransform.findAndFix(maybeFixed.get());
return true;
Expand All @@ -19,6 +26,10 @@ public static boolean checkAndFix(final MethodCallExpr methodCallExpr) {
}
}

/**
* Check if the {@link MethodCallExpr} is a JDBC API query method that is a target of a SQL
* injection transformation.
*/
public static boolean match(final MethodCallExpr methodCallExpr) {
return SQLParameterizer.isSupportedJdbcMethodCall(methodCallExpr)
|| SQLTableInjectionFilterTransform.matchCall(methodCallExpr);
Expand Down

0 comments on commit 3102d01

Please sign in to comment.