-
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.
Add several Sonar hotspot mappings (#486)
- Loading branch information
Showing
122 changed files
with
1,183 additions
and
75 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
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
2 changes: 1 addition & 1 deletion
2
...r/codemods/AddMissingOverrideCodemod.java → ...mods/sonar/AddMissingOverrideCodemod.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
2 changes: 1 addition & 1 deletion
2
...voidImplicitPublicConstructorCodemod.java → ...voidImplicitPublicConstructorCodemod.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
2 changes: 1 addition & 1 deletion
2
...codemods/ConstantNameStringGenerator.java → ...ds/sonar/ConstantNameStringGenerator.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
2 changes: 1 addition & 1 deletion
2
...er/codemods/CreateConstantForLiteral.java → ...emods/sonar/CreateConstantForLiteral.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
2 changes: 1 addition & 1 deletion
2
...demods/DeclareVariableOnSeparateLine.java → .../sonar/DeclareVariableOnSeparateLine.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
2 changes: 1 addition & 1 deletion
2
...DeclareVariableOnSeparateLineCodemod.java → ...DeclareVariableOnSeparateLineCodemod.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
2 changes: 1 addition & 1 deletion
2
...bleOnSeparateLineForFieldDeclaration.java → ...bleOnSeparateLineForFieldDeclaration.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
2 changes: 1 addition & 1 deletion
2
...parateLineForVariableDeclarationExpr.java → ...parateLineForVariableDeclarationExpr.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
2 changes: 1 addition & 1 deletion
2
...er/codemods/DefineConstantForLiteral.java → ...emods/sonar/DefineConstantForLiteral.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
2 changes: 1 addition & 1 deletion
2
...mods/DefineConstantForLiteralCodemod.java → ...onar/DefineConstantForLiteralCodemod.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
2 changes: 1 addition & 1 deletion
2
...mods/FixRedundantStaticOnEnumCodemod.java → ...onar/FixRedundantStaticOnEnumCodemod.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
2 changes: 1 addition & 1 deletion
2
...HardenStringParseToPrimitivesCodemod.java → ...HardenStringParseToPrimitivesCodemod.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
2 changes: 1 addition & 1 deletion
2
...desMatchParentSynchronizationCodemod.java → ...desMatchParentSynchronizationCodemod.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
2 changes: 1 addition & 1 deletion
2
.../codemods/RemoveCommentedCodeCodemod.java → ...ods/sonar/RemoveCommentedCodeCodemod.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
2 changes: 1 addition & 1 deletion
2
...moveRedundantVariableCreationCodemod.java → ...moveRedundantVariableCreationCodemod.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
2 changes: 1 addition & 1 deletion
2
...r/codemods/RemoveUnusedImportCodemod.java → ...mods/sonar/RemoveUnusedImportCodemod.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
2 changes: 1 addition & 1 deletion
2
...ods/RemoveUnusedLocalVariableCodemod.java → ...nar/RemoveUnusedLocalVariableCodemod.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
2 changes: 1 addition & 1 deletion
2
...ods/RemoveUnusedPrivateMethodCodemod.java → ...nar/RemoveUnusedPrivateMethodCodemod.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
2 changes: 1 addition & 1 deletion
2
...mods/RemoveUselessParenthesesCodemod.java → ...onar/RemoveUselessParenthesesCodemod.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
2 changes: 1 addition & 1 deletion
2
...ReplaceStreamCollectorsToListCodemod.java → ...ReplaceStreamCollectorsToListCodemod.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
2 changes: 1 addition & 1 deletion
2
...lifyRestControllerAnnotationsCodemod.java → ...lifyRestControllerAnnotationsCodemod.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
62 changes: 62 additions & 0 deletions
62
...emods/src/main/java/io/codemodder/codemods/sonar/SonarCookieMissingSecureFlagCodemod.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,62 @@ | ||
package io.codemodder.codemods.sonar; | ||
|
||
import com.github.javaparser.ast.CompilationUnit; | ||
import io.codemodder.*; | ||
import io.codemodder.codetf.DetectorRule; | ||
import io.codemodder.providers.sonar.ProvidedSonarScan; | ||
import io.codemodder.providers.sonar.RuleHotspot; | ||
import io.codemodder.providers.sonar.SonarRemediatingJavaParserChanger; | ||
import io.codemodder.remediation.GenericRemediationMetadata; | ||
import io.codemodder.remediation.Remediator; | ||
import io.codemodder.remediation.missingsecureflag.MissingSecureFlagRemediator; | ||
import io.codemodder.sonar.model.Hotspot; | ||
import io.codemodder.sonar.model.SonarFinding; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import javax.inject.Inject; | ||
|
||
@Codemod( | ||
id = "sonar:java/cookie-missing-secure-flag-2092", | ||
reviewGuidance = ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW, | ||
importance = Importance.HIGH, | ||
executionPriority = CodemodExecutionPriority.HIGH) | ||
public final class SonarCookieMissingSecureFlagCodemod extends SonarRemediatingJavaParserChanger { | ||
|
||
private final Remediator<Hotspot> remediationStrategy; | ||
private final RuleHotspot issues; | ||
|
||
@Inject | ||
public SonarCookieMissingSecureFlagCodemod( | ||
@ProvidedSonarScan(ruleId = "java:S2092") final RuleHotspot hotspots) { | ||
super(GenericRemediationMetadata.MISSING_SECURE_FLAG.reporter(), hotspots); | ||
this.issues = Objects.requireNonNull(hotspots); | ||
this.remediationStrategy = new MissingSecureFlagRemediator<>(); | ||
} | ||
|
||
@Override | ||
public DetectorRule detectorRule() { | ||
return new DetectorRule( | ||
"java:S2092", | ||
"Make sure creating this cookie without the \"secure\" flag is safe here.", | ||
"https://rules.sonarsource.com/java/type/Security%20Hotspot/RSPEC-2092/"); | ||
} | ||
|
||
@Override | ||
public CodemodFileScanningResult visit( | ||
final CodemodInvocationContext context, final CompilationUnit cu) { | ||
List<Hotspot> issuesForFile = issues.getResultsByPath(context.path()); | ||
return remediationStrategy.remediateAll( | ||
cu, | ||
context.path().toString(), | ||
detectorRule(), | ||
issuesForFile, | ||
SonarFinding::getKey, | ||
i -> i.getTextRange() != null ? i.getTextRange().getStartLine() : i.getLine(), | ||
i -> | ||
i.getTextRange() != null | ||
? Optional.of(i.getTextRange().getEndLine()) | ||
: Optional.empty(), | ||
i -> Optional.empty()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...r/codemods/SonarJNDIInjectionCodemod.java → ...mods/sonar/SonarJNDIInjectionCodemod.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
2 changes: 1 addition & 1 deletion
2
...ds/SonarObjectDeserializationCodemod.java → ...ar/SonarObjectDeserializationCodemod.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
2 changes: 1 addition & 1 deletion
2
...narRemoveUnthrowableExceptionCodemod.java → ...narRemoveUnthrowableExceptionCodemod.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
2 changes: 1 addition & 1 deletion
2
...er/codemods/SonarSQLInjectionCodemod.java → ...emods/sonar/SonarSQLInjectionCodemod.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
2 changes: 1 addition & 1 deletion
2
...codemodder/codemods/SonarSSRFCodemod.java → ...dder/codemods/sonar/SonarSSRFCodemod.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
2 changes: 1 addition & 1 deletion
2
...arUnsafeReflectionRemediationCodemod.java → ...arUnsafeReflectionRemediationCodemod.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
62 changes: 62 additions & 0 deletions
62
...codemods/src/main/java/io/codemodder/codemods/sonar/SonarWeakHashingAlgorithmCodemod.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,62 @@ | ||
package io.codemodder.codemods.sonar; | ||
|
||
import com.github.javaparser.ast.CompilationUnit; | ||
import io.codemodder.*; | ||
import io.codemodder.codetf.DetectorRule; | ||
import io.codemodder.providers.sonar.ProvidedSonarScan; | ||
import io.codemodder.providers.sonar.RuleHotspot; | ||
import io.codemodder.providers.sonar.SonarRemediatingJavaParserChanger; | ||
import io.codemodder.remediation.GenericRemediationMetadata; | ||
import io.codemodder.remediation.Remediator; | ||
import io.codemodder.remediation.weakcrypto.WeakCryptoAlgorithmRemediator; | ||
import io.codemodder.sonar.model.Hotspot; | ||
import io.codemodder.sonar.model.SonarFinding; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import javax.inject.Inject; | ||
|
||
@Codemod( | ||
id = "sonar:java/weak-hash-4790", | ||
reviewGuidance = ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW, | ||
importance = Importance.HIGH, | ||
executionPriority = CodemodExecutionPriority.HIGH) | ||
public final class SonarWeakHashingAlgorithmCodemod extends SonarRemediatingJavaParserChanger { | ||
|
||
private final Remediator<Hotspot> remediationStrategy; | ||
private final RuleHotspot issues; | ||
|
||
@Inject | ||
public SonarWeakHashingAlgorithmCodemod( | ||
@ProvidedSonarScan(ruleId = "java:S4790") final RuleHotspot hotspots) { | ||
super(GenericRemediationMetadata.WEAK_CRYPTO_ALGORITHM.reporter(), hotspots); | ||
this.issues = Objects.requireNonNull(hotspots); | ||
this.remediationStrategy = new WeakCryptoAlgorithmRemediator<>(); | ||
} | ||
|
||
@Override | ||
public DetectorRule detectorRule() { | ||
return new DetectorRule( | ||
"java:S4790", | ||
"Using weak hashing algorithms is security-sensitive", | ||
"https://rules.sonarsource.com/java/type/Security%20Hotspot/RSPEC-4790/"); | ||
} | ||
|
||
@Override | ||
public CodemodFileScanningResult visit( | ||
final CodemodInvocationContext context, final CompilationUnit cu) { | ||
List<Hotspot> issuesForFile = issues.getResultsByPath(context.path()); | ||
return remediationStrategy.remediateAll( | ||
cu, | ||
context.path().toString(), | ||
detectorRule(), | ||
issuesForFile, | ||
SonarFinding::getKey, | ||
i -> i.getTextRange() != null ? i.getTextRange().getStartLine() : i.getLine(), | ||
i -> | ||
i.getTextRange() != null | ||
? Optional.of(i.getTextRange().getEndLine()) | ||
: Optional.empty(), | ||
i -> Optional.empty()); | ||
} | ||
} |
Oops, something went wrong.