Skip to content

Commit ff303db

Browse files
committed
Autoformat and fix qhelp
1 parent 303927c commit ff303db

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

java/ql/src/experimental/Security/CWE/CWE-208/TimingAttackAgainstHeader.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ and does not depend on the contents of the arrays.
2222
The following example uses <code>String.equals()</code> method for validating a csrf token.
2323
This method implements a non-constant-time algorithm. The example also demonstrates validation using a safe constant-time algorithm.
2424
</p>
25-
<sample src="ComparingValueOfSensetiveHeader.java" />
25+
<sample src="TimingAttackAgainstHeader.java" />
2626
</example>
2727
</qhelp>
2828

java/ql/src/experimental/Security/CWE/CWE-208/TimingAttackAgainstHeader.ql

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* external/cwe/cwe-208
1111
*/
1212

13-
1413
import java
1514
import semmle.code.java.dataflow.FlowSources
1615
import semmle.code.java.dataflow.TaintTracking
@@ -28,29 +27,26 @@ private class NonConstantTimeComparisonCall extends StaticMethodAccess {
2827
/** Methods that use a non-constant-time algorithm for comparing inputs. */
2928
private class NonConstantTimeEqualsCall extends MethodAccess {
3029
NonConstantTimeEqualsCall() {
31-
this.getMethod().hasQualifiedName("java.lang", "String", ["equals", "contentEquals", "equalsIgnoreCase"])
30+
this.getMethod()
31+
.hasQualifiedName("java.lang", "String", ["equals", "contentEquals", "equalsIgnoreCase"])
3232
}
3333
}
3434

3535
private predicate isNonConstantEqualsCallArgument(Expr e) {
36-
exists(NonConstantTimeEqualsCall call |
37-
e = [call.getQualifier(), call.getArgument(0)]
38-
)
36+
exists(NonConstantTimeEqualsCall call | e = [call.getQualifier(), call.getArgument(0)])
3937
}
4038

4139
private predicate isNonConstantComparisonCallArgument(Expr p) {
42-
exists(NonConstantTimeComparisonCall call |
43-
p = [call.getArgument(0), call.getArgument(1)]
44-
)
40+
exists(NonConstantTimeComparisonCall call | p = [call.getArgument(0), call.getArgument(1)])
4541
}
4642

4743
class ClientSuppliedIpTokenCheck extends DataFlow::Node {
4844
ClientSuppliedIpTokenCheck() {
4945
exists(MethodAccess ma |
5046
ma.getMethod().hasName("getHeader") and
5147
ma.getArgument(0).(CompileTimeConstantExpr).getStringValue().toLowerCase() in [
52-
"x-auth-token", "x-csrf-token", "http_x_csrf_token", "x-csrf-param", "x-csrf-header",
53-
"http_x_csrf_token", "x-api-key", "authorization", "proxy-authorization"
48+
"x-auth-token", "x-csrf-token", "http_x_csrf_token", "x-csrf-param", "x-csrf-header",
49+
"http_x_csrf_token", "x-api-key", "authorization", "proxy-authorization"
5450
] and
5551
ma = this.asExpr()
5652
)
@@ -60,14 +56,17 @@ class ClientSuppliedIpTokenCheck extends DataFlow::Node {
6056
class NonConstantTimeComparisonConfig extends TaintTracking::Configuration {
6157
NonConstantTimeComparisonConfig() { this = "NonConstantTimeComparisonConfig" }
6258

63-
override predicate isSource(DataFlow::Node source) { source instanceof ClientSuppliedIpTokenCheck }
59+
override predicate isSource(DataFlow::Node source) {
60+
source instanceof ClientSuppliedIpTokenCheck
61+
}
6462

65-
override predicate isSink(DataFlow::Node sink) {
66-
isNonConstantEqualsCallArgument(sink.asExpr()) or
63+
override predicate isSink(DataFlow::Node sink) {
64+
isNonConstantEqualsCallArgument(sink.asExpr()) or
6765
isNonConstantComparisonCallArgument(sink.asExpr())
6866
}
6967
}
7068

7169
from DataFlow::PathNode source, DataFlow::PathNode sink, NonConstantTimeComparisonConfig conf
7270
where conf.hasFlowPath(source, sink)
73-
select sink.getNode(), source, sink, "Possible timing attack against $@ validation.", source.getNode()
71+
select sink.getNode(), source, sink, "Possible timing attack against $@ validation.",
72+
source.getNode()

0 commit comments

Comments
 (0)