Skip to content

Commit 30178d4

Browse files
committed
Decouple InsecureBasicAuth.qll to reuse the taint tracking configuration
1 parent 90df3fa commit 30178d4

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

java/ql/src/Security/CWE/CWE-522/InsecureBasicAuth.ql

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,9 @@
1414
*/
1515

1616
import java
17-
import semmle.code.java.dataflow.TaintTracking
18-
import semmle.code.java.security.InsecureBasicAuth
17+
import semmle.code.java.security.InsecureBasicAuthQuery
1918
import DataFlow::PathGraph
2019

21-
class BasicAuthFlowConfig extends TaintTracking::Configuration {
22-
BasicAuthFlowConfig() { this = "InsecureBasicAuth::BasicAuthFlowConfig" }
23-
24-
override predicate isSource(DataFlow::Node src) { src instanceof InsecureBasicAuthSource }
25-
26-
override predicate isSink(DataFlow::Node sink) { sink instanceof InsecureBasicAuthSink }
27-
28-
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
29-
any(InsecureBasicAuthAdditionalTaintStep c).step(node1, node2)
30-
}
31-
}
32-
3320
from DataFlow::PathNode source, DataFlow::PathNode sink, BasicAuthFlowConfig config
3421
where config.hasFlowPath(source, sink)
3522
select sink.getNode(), source, sink, "Insecure basic authentication from $@.", source.getNode(),

java/ql/src/semmle/code/java/security/InsecureBasicAuth.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private class DefaultInsecureBasicAuthSource extends InsecureBasicAuthSource {
3030
}
3131

3232
/**
33-
* A sink that represents a method that set Basic Authentication.
33+
* A sink that represents a method that sets Basic Authentication.
3434
* Extend this class to add your own Insecure Basic Authentication sinks.
3535
*/
3636
abstract class InsecureBasicAuthSink extends DataFlow::Node { }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** Provides taint tracking configurations to be used in Insecure Basic Authentication queries. */
2+
3+
import java
4+
import semmle.code.java.security.InsecureBasicAuth
5+
import semmle.code.java.dataflow.TaintTracking
6+
7+
/**
8+
* A taint tracking configuration for the Basic authentication scheme
9+
* being used in HTTP connections.
10+
*/
11+
class BasicAuthFlowConfig extends TaintTracking::Configuration {
12+
BasicAuthFlowConfig() { this = "InsecureBasicAuth::BasicAuthFlowConfig" }
13+
14+
override predicate isSource(DataFlow::Node src) { src instanceof InsecureBasicAuthSource }
15+
16+
override predicate isSink(DataFlow::Node sink) { sink instanceof InsecureBasicAuthSink }
17+
18+
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
19+
any(InsecureBasicAuthAdditionalTaintStep c).step(node1, node2)
20+
}
21+
}

java/ql/test/query-tests/security/CWE-522/InsecureBasicAuthTest.ql

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
import java
2-
import semmle.code.java.dataflow.TaintTracking
3-
import semmle.code.java.dataflow.FlowSources
4-
import semmle.code.java.security.InsecureBasicAuth
2+
import semmle.code.java.security.InsecureBasicAuthQuery
53
import TestUtilities.InlineExpectationsTest
64

7-
class Conf extends TaintTracking::Configuration {
8-
Conf() { this = "test:cwe:insecure-basic-auth" }
9-
10-
override predicate isSource(DataFlow::Node src) { src instanceof InsecureBasicAuthSource }
11-
12-
override predicate isSink(DataFlow::Node sink) { sink instanceof InsecureBasicAuthSink }
13-
14-
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
15-
any(InsecureBasicAuthAdditionalTaintStep c).step(node1, node2)
16-
}
17-
}
18-
195
class HasInsecureBasicAuthTest extends InlineExpectationsTest {
206
HasInsecureBasicAuthTest() { this = "HasInsecureBasicAuthTest" }
217

228
override string getARelevantTag() { result = "hasInsecureBasicAuth" }
239

2410
override predicate hasActualResult(Location location, string element, string tag, string value) {
2511
tag = "hasInsecureBasicAuth" and
26-
exists(DataFlow::Node src, DataFlow::Node sink, Conf conf | conf.hasFlow(src, sink) |
12+
exists(DataFlow::Node src, DataFlow::Node sink, BasicAuthFlowConfig conf |
13+
conf.hasFlow(src, sink)
14+
|
2715
sink.getLocation() = location and
2816
element = sink.toString() and
2917
value = ""

0 commit comments

Comments
 (0)