-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve XSS fixer and create CodeQL mapping (#467)
- Loading branch information
Showing
6 changed files
with
222 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
55 changes: 55 additions & 0 deletions
55
core-codemods/src/main/java/io/codemodder/codemods/codeql/CodeQLXSSCodemod.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.codemodder.codemods.codeql; | ||
|
||
import com.contrastsecurity.sarif.Result; | ||
import com.github.javaparser.ast.CompilationUnit; | ||
import io.codemodder.*; | ||
import io.codemodder.codetf.DetectorRule; | ||
import io.codemodder.providers.sarif.codeql.ProvidedCodeQLScan; | ||
import io.codemodder.remediation.GenericRemediationMetadata; | ||
import io.codemodder.remediation.Remediator; | ||
import io.codemodder.remediation.xss.XSSRemediator; | ||
import java.util.Optional; | ||
import javax.inject.Inject; | ||
|
||
/** A codemod for automatically fixing XSS from CodeQL. */ | ||
@Codemod( | ||
id = "codeql:java/xss", | ||
reviewGuidance = ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW, | ||
importance = Importance.HIGH, | ||
executionPriority = CodemodExecutionPriority.HIGH) | ||
public final class CodeQLXSSCodemod extends CodeQLRemediationCodemod { | ||
|
||
private final Remediator<Result> remediator; | ||
|
||
@Inject | ||
public CodeQLXSSCodemod(@ProvidedCodeQLScan(ruleId = "java/xss") final RuleSarif sarif) { | ||
super(GenericRemediationMetadata.XSS.reporter(), sarif); | ||
this.remediator = new XSSRemediator<>(); | ||
} | ||
|
||
@Override | ||
public DetectorRule detectorRule() { | ||
return new DetectorRule( | ||
"xss", | ||
"Cross-site scripting", | ||
"https://codeql.github.com/codeql-query-help/java/java-xss/"); | ||
} | ||
|
||
@Override | ||
public CodemodFileScanningResult visit( | ||
final CodemodInvocationContext context, final CompilationUnit cu) { | ||
return remediator.remediateAll( | ||
cu, | ||
context.path().toString(), | ||
detectorRule(), | ||
ruleSarif.getResultsByLocationPath(context.path()), | ||
SarifFindingKeyUtil::buildFindingId, | ||
r -> r.getLocations().get(0).getPhysicalLocation().getRegion().getStartLine(), | ||
r -> | ||
Optional.ofNullable( | ||
r.getLocations().get(0).getPhysicalLocation().getRegion().getEndLine()), | ||
r -> | ||
Optional.ofNullable( | ||
r.getLocations().get(0).getPhysicalLocation().getRegion().getStartColumn())); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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