Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

Commit 7cd5035

Browse files
committed
wip, add cwe/owasp
1 parent e210b0e commit 7cd5035

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

src/main/java/com/hack23/sonar/CloudformationRulesDefinition.java

+27-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import java.io.InputStream;
44
import java.nio.charset.StandardCharsets;
5+
import java.util.Set;
56

7+
import org.apache.commons.lang3.reflect.FieldUtils;
68
import org.sonar.api.server.rule.RulesDefinition;
79
import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
10+
import org.sonar.api.server.rule.RulesDefinition.NewRule;
11+
import org.sonar.api.server.rule.RulesDefinition.OwaspTop10;
812

913
public class CloudformationRulesDefinition implements RulesDefinition {
1014

@@ -27,10 +31,31 @@ private void defineRulesForLanguage(Context context, String repositoryKey, Strin
2731
if (rulesXml != null) {
2832
RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader();
2933
rulesLoader.load(repository, rulesXml, StandardCharsets.UTF_8.name());
30-
}
31-
34+
35+
36+
for (NewRule newRule : repository.rules()) {
37+
38+
try {
39+
final Set<String> tags = (Set<String>) FieldUtils.readField(newRule, "tags", true);
40+
for (String tag : tags) {
41+
42+
if (tag.contains("cweid-")) {
43+
newRule.addCwe(Integer.parseInt(tag.replace("cweid-", "")));
44+
}
45+
46+
if (tag.contains("owasp-")) {
47+
newRule.addOwaspTop10(OwaspTop10.valueOf(tag.replace("owasp-", "").toUpperCase()));
48+
}
49+
}
50+
} catch (IllegalAccessException e) {
51+
//LOGGER.warn("Problem parsing security tags",e);
52+
}
53+
}
54+
}
3255
repository.done();
56+
3357
}
58+
3459

3560
@Override
3661
public void define(Context context) {

src/main/resources/cloudformation-rules.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<status>READY</status>
1010
<type>VULNERABILITY</type>
1111
<tag>owasp-a6</tag>
12-
<tag>cwe-311</tag>
12+
<tag>cweid-311</tag>
1313
<remediationFunction>CONSTANT_ISSUE</remediationFunction>
1414
<remediationFunctionBaseEffort>10min</remediationFunctionBaseEffort>
1515
</rule>

0 commit comments

Comments
 (0)