Skip to content

Commit 9170c87

Browse files
authored
Update CodeQL rule ID for stack-trace-exposure (#440)
Updated rule ID since CodeQL changed. We may one day want to support multiple rule IDs.
1 parent f067232 commit 9170c87

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

core-codemods/src/main/java/io/codemodder/codemods/StackTraceExposureCodemod.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313
import io.codemodder.providers.sarif.codeql.ProvidedCodeQLScan;
1414
import javax.inject.Inject;
1515

16-
/** Fixes issues reported under the id "java/stack-trace-exposure" */
16+
/**
17+
* Fixes issues reported under the id "java/java-error-message-exposure" (used to be
18+
* java-stack-trace-exposure).
19+
*/
1720
@Codemod(
18-
id = "codeql:java/stack-trace-exposure",
21+
id = "codeql:java/error-message-exposure",
1922
reviewGuidance = ReviewGuidance.MERGE_WITHOUT_REVIEW,
2023
importance = Importance.MEDIUM,
2124
executionPriority = CodemodExecutionPriority.HIGH)
2225
public final class StackTraceExposureCodemod extends CodeQLSarifJavaParserChanger<Expression> {
2326

2427
@Inject
2528
public StackTraceExposureCodemod(
26-
@ProvidedCodeQLScan(ruleId = "java/stack-trace-exposure") final RuleSarif sarif) {
29+
@ProvidedCodeQLScan(ruleId = "java/error-message-exposure") final RuleSarif sarif) {
2730
super(sarif, Expression.class, SourceCodeRegionExtractor.FROM_SARIF_FIRST_LOCATION);
2831
}
2932

@@ -57,8 +60,8 @@ public ChangesResult onResultFound(
5760
@Override
5861
public DetectorRule detectorRule() {
5962
return new DetectorRule(
60-
"stack-trace-exposure",
63+
"error-message-exposure",
6164
"Prevent information leak of stack trace details to HTTP responses",
62-
"https://codeql.github.com/codeql-query-help/java/java-stack-trace-exposure/");
65+
"https://codeql.github.com/codeql-query-help/java/java-error-message-exposure/");
6366
}
6467
}

core-codemods/src/main/resources/io/codemodder/codemods/StackTraceExposureCodemod/report.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"change": "Removed the argument which would end up exposed in the HTTP response and leak implementation details of our application to the user",
44
"reviewGuidanceJustification" : "This codemod prevents internal coding details from reaching the HTTP response body, and we believe that fixing it presents zero risk.",
55
"references" : [
6-
"https://codeql.github.com/codeql-query-help/java/java-stack-trace-exposure/",
6+
"https://codeql.github.com/codeql-query-help/java/java-error-message-exposure/",
77
"https://cwe.mitre.org/data/definitions/209.html",
88
"https://cwe.mitre.org/data/definitions/497.html"
99
]

core-codemods/src/test/resources/stack-trace-exposure/out.sarif

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"organization" : "GitHub",
99
"semanticVersion" : "2.11.6",
1010
"rules" : [ {
11-
"id" : "java/stack-trace-exposure",
12-
"name" : "java/stack-trace-exposure",
11+
"id" : "java/error-message-exposure",
12+
"name" : "java/error-message-exposure",
1313
"shortDescription" : {
1414
"text" : "Information exposure through a stack trace"
1515
},
@@ -23,7 +23,7 @@
2323
"properties" : {
2424
"tags" : [ "security", "external/cwe/cwe-209", "external/cwe/cwe-497" ],
2525
"description" : "Information from a stack trace propagates to an external user.\n Stack traces can unintentionally reveal implementation details\n that are useful to an attacker for developing a subsequent exploit.",
26-
"id" : "java/stack-trace-exposure",
26+
"id" : "java/error-message-exposure",
2727
"kind" : "problem",
2828
"name" : "Information exposure through a stack trace",
2929
"precision" : "high",
@@ -70,10 +70,10 @@
7070
}
7171
} ],
7272
"results" : [ {
73-
"ruleId" : "java/stack-trace-exposure",
73+
"ruleId" : "java/error-message-exposure",
7474
"ruleIndex" : 0,
7575
"rule" : {
76-
"id" : "java/stack-trace-exposure",
76+
"id" : "java/error-message-exposure",
7777
"index" : 0
7878
},
7979
"message" : {
@@ -116,10 +116,10 @@
116116
}
117117
} ]
118118
}, {
119-
"ruleId" : "java/stack-trace-exposure",
119+
"ruleId" : "java/error-message-exposure",
120120
"ruleIndex" : 0,
121121
"rule" : {
122-
"id" : "java/stack-trace-exposure",
122+
"id" : "java/error-message-exposure",
123123
"index" : 0
124124
},
125125
"message" : {
@@ -162,10 +162,10 @@
162162
}
163163
} ]
164164
}, {
165-
"ruleId" : "java/stack-trace-exposure",
165+
"ruleId" : "java/error-message-exposure",
166166
"ruleIndex" : 0,
167167
"rule" : {
168-
"id" : "java/stack-trace-exposure",
168+
"id" : "java/error-message-exposure",
169169
"index" : 0
170170
},
171171
"message" : {

core-codemods/src/test/resources/webgoat_v8.2.2_codeql.sarif

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4090,8 +4090,8 @@
40904090
"markdown": "# Information exposure through a stack trace\nSoftware developers often add stack traces to error messages, as a debugging aid. Whenever that error message occurs for an end user, the developer can use the stack trace to help identify how to fix the problem. In particular, stack traces can tell the developer more about the sequence of events that led to a failure, as opposed to merely the final state of the software when the error occurred.\n\nUnfortunately, the same information can be useful to an attacker. The sequence of class names in a stack trace can reveal the structure of the application as well as any internal components it relies on. Furthermore, the error message at the top of a stack trace can include information such as server-side file names and SQL code that the application relies on, allowing an attacker to fine-tune a subsequent injection attack.\n\n\n## Recommendation\nSend the user a more generic error message that reveals less information. Either suppress the stack trace entirely, or log it only on the server.\n\n\n## Example\nIn the following example, an exception is handled in two different ways. In the first version, labeled BAD, the exception is sent back to the remote user using the `sendError()` method. As such, the user is able to see a detailed stack trace, which may contain sensitive information. In the second version, the error message is logged only on the server. That way, the developers can still access and use the error log, but remote users will not see the information.\n\n\n```java\nprotected void doGet(HttpServletRequest request, HttpServletResponse response) {\n\ttry {\n\t\tdoSomeWork();\n\t} catch (NullPointerException ex) {\n\t\t// BAD: printing a stack trace back to the response\n\t\tex.printStackTrace(response.getWriter());\n\t\treturn;\n\t}\n\n\ttry {\n\t\tdoSomeWork();\n\t} catch (NullPointerException ex) {\n\t\t// GOOD: log the stack trace, and send back a non-revealing response\n\t\tlog(\"Exception occurred\", ex);\n\t\tresponse.sendError(\n\t\t\tHttpServletResponse.SC_INTERNAL_SERVER_ERROR,\n\t\t\t\"Exception occurred\");\n\t\treturn;\n\t}\n}\n\n```\n\n## References\n* OWASP: [Improper Error Handling](https://owasp.org/www-community/Improper_Error_Handling).\n* CERT Java Coding Standard: [ERR01-J. Do not allow exceptions to expose sensitive information](https://www.securecoding.cert.org/confluence/display/java/ERR01-J.+Do+not+allow+exceptions+to+expose+sensitive+information).\n* Common Weakness Enumeration: [CWE-209](https://cwe.mitre.org/data/definitions/209.html).\n* Common Weakness Enumeration: [CWE-497](https://cwe.mitre.org/data/definitions/497.html).\n",
40914091
"text": "# Information exposure through a stack trace\nSoftware developers often add stack traces to error messages, as a debugging aid. Whenever that error message occurs for an end user, the developer can use the stack trace to help identify how to fix the problem. In particular, stack traces can tell the developer more about the sequence of events that led to a failure, as opposed to merely the final state of the software when the error occurred.\n\nUnfortunately, the same information can be useful to an attacker. The sequence of class names in a stack trace can reveal the structure of the application as well as any internal components it relies on. Furthermore, the error message at the top of a stack trace can include information such as server-side file names and SQL code that the application relies on, allowing an attacker to fine-tune a subsequent injection attack.\n\n\n## Recommendation\nSend the user a more generic error message that reveals less information. Either suppress the stack trace entirely, or log it only on the server.\n\n\n## Example\nIn the following example, an exception is handled in two different ways. In the first version, labeled BAD, the exception is sent back to the remote user using the `sendError()` method. As such, the user is able to see a detailed stack trace, which may contain sensitive information. In the second version, the error message is logged only on the server. That way, the developers can still access and use the error log, but remote users will not see the information.\n\n\n```java\nprotected void doGet(HttpServletRequest request, HttpServletResponse response) {\n\ttry {\n\t\tdoSomeWork();\n\t} catch (NullPointerException ex) {\n\t\t// BAD: printing a stack trace back to the response\n\t\tex.printStackTrace(response.getWriter());\n\t\treturn;\n\t}\n\n\ttry {\n\t\tdoSomeWork();\n\t} catch (NullPointerException ex) {\n\t\t// GOOD: log the stack trace, and send back a non-revealing response\n\t\tlog(\"Exception occurred\", ex);\n\t\tresponse.sendError(\n\t\t\tHttpServletResponse.SC_INTERNAL_SERVER_ERROR,\n\t\t\t\"Exception occurred\");\n\t\treturn;\n\t}\n}\n\n```\n\n## References\n* OWASP: [Improper Error Handling](https://owasp.org/www-community/Improper_Error_Handling).\n* CERT Java Coding Standard: [ERR01-J. Do not allow exceptions to expose sensitive information](https://www.securecoding.cert.org/confluence/display/java/ERR01-J.+Do+not+allow+exceptions+to+expose+sensitive+information).\n* Common Weakness Enumeration: [CWE-209](https://cwe.mitre.org/data/definitions/209.html).\n* Common Weakness Enumeration: [CWE-497](https://cwe.mitre.org/data/definitions/497.html).\n"
40924092
},
4093-
"id": "java/stack-trace-exposure",
4094-
"name": "java/stack-trace-exposure",
4093+
"id": "java/error-message-exposure",
4094+
"name": "java/error-message-exposure",
40954095
"properties": {
40964096
"security-severity": "5.400000",
40974097
"tags": [

0 commit comments

Comments
 (0)