Skip to content

Commit 47b9218

Browse files
authored
Merge pull request #480 from aschackmull/java/path-problem-conversion
Java: Convert security queries to path-problem.
2 parents 0647743 + 918fc90 commit 47b9218

File tree

64 files changed

+758
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+758
-397
lines changed

change-notes/1.19/analysis-java.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## General improvements
44

5+
* Where applicable, path explanations have been added to the security queries.
6+
57
## New queries
68

79
| **Query** | **Tags** | **Purpose** |

java/ql/src/Security/CWE/CWE-022/TaintedPath.ql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Uncontrolled data used in path expression
33
* @description Accessing paths influenced by users can allow an attacker to access unexpected resources.
4-
* @kind problem
4+
* @kind path-problem
55
* @problem.severity error
66
* @precision high
77
* @id java/path-injection
@@ -15,6 +15,7 @@
1515
import java
1616
import semmle.code.java.dataflow.FlowSources
1717
import PathsCommon
18+
import DataFlow::PathGraph
1819

1920
class TaintedPathConfig extends TaintTracking::Configuration {
2021
TaintedPathConfig() { this = "TaintedPathConfig" }
@@ -30,8 +31,9 @@ class TaintedPathConfig extends TaintTracking::Configuration {
3031
}
3132
}
3233

33-
from RemoteUserInput u, PathCreation p, Expr e, TaintedPathConfig conf
34+
from DataFlow::PathNode source, DataFlow::PathNode sink, PathCreation p, TaintedPathConfig conf
3435
where
35-
e = p.getInput() and
36-
conf.hasFlow(u, DataFlow::exprNode(e))
37-
select p, "$@ flows to here and is used in a path.", u, "User-provided value"
36+
sink.getNode().asExpr() = p.getInput() and
37+
conf.hasFlowPath(source, sink)
38+
select p, source, sink, "$@ flows to here and is used in a path.", source.getNode(),
39+
"User-provided value"

java/ql/src/Security/CWE/CWE-022/TaintedPathLocal.ql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Local-user-controlled data in path expression
33
* @description Accessing paths influenced by users can allow an attacker to access unexpected resources.
4-
* @kind problem
4+
* @kind path-problem
55
* @problem.severity recommendation
66
* @precision medium
77
* @id java/path-injection-local
@@ -15,6 +15,7 @@
1515
import java
1616
import semmle.code.java.dataflow.FlowSources
1717
import PathsCommon
18+
import DataFlow::PathGraph
1819

1920
class TaintedPathLocalConfig extends TaintTracking::Configuration {
2021
TaintedPathLocalConfig() { this = "TaintedPathLocalConfig" }
@@ -24,9 +25,13 @@ class TaintedPathLocalConfig extends TaintTracking::Configuration {
2425
override predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(PathCreation p).getInput() }
2526
}
2627

27-
from LocalUserInput u, PathCreation p, Expr e, TaintedPathLocalConfig conf
28+
from
29+
DataFlow::PathNode source, DataFlow::PathNode sink, PathCreation p, Expr e,
30+
TaintedPathLocalConfig conf
2831
where
32+
e = sink.getNode().asExpr() and
2933
e = p.getInput() and
30-
conf.hasFlow(u, DataFlow::exprNode(e)) and
34+
conf.hasFlowPath(source, sink) and
3135
not guarded(e)
32-
select p, "$@ flows to here and is used in a path.", u, "User-provided value"
36+
select p, source, sink, "$@ flows to here and is used in a path.", source.getNode(),
37+
"User-provided value"

java/ql/src/Security/CWE/CWE-022/ZipSlip.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @description Extracting files from a malicious archive without validating that the
44
* destination file path is within the destination directory can cause files outside
55
* the destination directory to be overwritten.
6-
* @kind problem
6+
* @kind path-problem
77
* @id java/zipslip
88
* @problem.severity error
99
* @precision high
@@ -16,6 +16,7 @@ import semmle.code.java.controlflow.Guards
1616
import semmle.code.java.dataflow.SSA
1717
import semmle.code.java.dataflow.TaintTracking
1818
import DataFlow
19+
import PathGraph
1920

2021
/**
2122
* A method that returns the name of an archive entry.
@@ -170,7 +171,8 @@ class ZipSlipConfiguration extends TaintTracking::Configuration {
170171
}
171172
}
172173

173-
from Node source, Node sink
174-
where any(ZipSlipConfiguration c).hasFlow(source, sink)
175-
select source, "Unsanitized archive entry, which may contain '..', is used in a $@.", sink,
174+
from PathNode source, PathNode sink
175+
where any(ZipSlipConfiguration c).hasFlowPath(source, sink)
176+
select source.getNode(), source, sink,
177+
"Unsanitized archive entry, which may contain '..', is used in a $@.", sink.getNode(),
176178
"file system operation"

java/ql/src/Security/CWE/CWE-078/ExecCommon.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ private class RemoteUserInputToArgumentToExecFlowConfig extends TaintTracking::C
2020
* so that it can be excluded from `ExecUnescaped.ql` to avoid
2121
* reporting overlapping results.
2222
*/
23-
predicate execTainted(RemoteUserInput source, ArgumentToExec execArg) {
23+
predicate execTainted(DataFlow::PathNode source, DataFlow::PathNode sink, ArgumentToExec execArg) {
2424
exists(RemoteUserInputToArgumentToExecFlowConfig conf |
25-
conf.hasFlow(source, DataFlow::exprNode(execArg))
25+
conf.hasFlowPath(source, sink) and sink.getNode() = DataFlow::exprNode(execArg)
2626
)
2727
}

java/ql/src/Security/CWE/CWE-078/ExecTainted.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Uncontrolled command line
33
* @description Using externally controlled strings in a command line is vulnerable to malicious
44
* changes in the strings.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id java/command-line-injection
@@ -15,7 +15,9 @@ import semmle.code.java.Expr
1515
import semmle.code.java.dataflow.FlowSources
1616
import semmle.code.java.security.ExternalProcess
1717
import ExecCommon
18+
import DataFlow::PathGraph
1819

19-
from StringArgumentToExec execArg, RemoteUserInput origin
20-
where execTainted(origin, execArg)
21-
select execArg, "$@ flows to here and is used in a command.", origin, "User-provided value"
20+
from DataFlow::PathNode source, DataFlow::PathNode sink, StringArgumentToExec execArg
21+
where execTainted(source, sink, execArg)
22+
select execArg, source, sink, "$@ flows to here and is used in a command.", source.getNode(),
23+
"User-provided value"

java/ql/src/Security/CWE/CWE-078/ExecTaintedLocal.ql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Local-user-controlled command line
33
* @description Using externally controlled strings in a command line is vulnerable to malicious
44
* changes in the strings.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity recommendation
77
* @precision medium
88
* @id java/command-line-injection-local
@@ -14,6 +14,7 @@
1414
import semmle.code.java.Expr
1515
import semmle.code.java.dataflow.FlowSources
1616
import semmle.code.java.security.ExternalProcess
17+
import DataFlow::PathGraph
1718

1819
class LocalUserInputToArgumentToExecFlowConfig extends TaintTracking::Configuration {
1920
LocalUserInputToArgumentToExecFlowConfig() { this = "LocalUserInputToArgumentToExecFlowConfig" }
@@ -28,6 +29,8 @@ class LocalUserInputToArgumentToExecFlowConfig extends TaintTracking::Configurat
2829
}
2930

3031
from
31-
StringArgumentToExec execArg, LocalUserInput origin, LocalUserInputToArgumentToExecFlowConfig conf
32-
where conf.hasFlow(origin, DataFlow::exprNode(execArg))
33-
select execArg, "$@ flows to here and is used in a command.", origin, "User-provided value"
32+
DataFlow::PathNode source, DataFlow::PathNode sink, StringArgumentToExec execArg,
33+
LocalUserInputToArgumentToExecFlowConfig conf
34+
where conf.hasFlowPath(source, sink) and sink.getNode().asExpr() = execArg
35+
select execArg, source, sink, "$@ flows to here and is used in a command.", source.getNode(),
36+
"User-provided value"

java/ql/src/Security/CWE/CWE-078/ExecUnescaped.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ predicate builtFromUncontrolledConcat(Expr expr) {
4747
from StringArgumentToExec argument
4848
where
4949
builtFromUncontrolledConcat(argument) and
50-
not execTainted(_, argument)
50+
not execTainted(_, _, argument)
5151
select argument, "Command line is built with string concatenation."

java/ql/src/Security/CWE/CWE-079/XSS.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Cross-site scripting
33
* @description Writing user input directly to a web page
44
* allows for a cross-site scripting vulnerability.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id java/xss
@@ -13,6 +13,7 @@
1313
import java
1414
import semmle.code.java.dataflow.FlowSources
1515
import semmle.code.java.security.XSS
16+
import DataFlow2::PathGraph
1617

1718
class XSSConfig extends TaintTracking::Configuration2 {
1819
XSSConfig() { this = "XSSConfig" }
@@ -26,6 +27,7 @@ class XSSConfig extends TaintTracking::Configuration2 {
2627
}
2728
}
2829

29-
from XssSink sink, RemoteUserInput source, XSSConfig conf
30-
where conf.hasFlow(source, sink)
31-
select sink, "Cross-site scripting vulnerability due to $@.", source, "user-provided value"
30+
from DataFlow2::PathNode source, DataFlow2::PathNode sink, XSSConfig conf
31+
where conf.hasFlowPath(source, sink)
32+
select sink.getNode(), source, sink, "Cross-site scripting vulnerability due to $@.",
33+
source.getNode(), "user-provided value"

java/ql/src/Security/CWE/CWE-079/XSSLocal.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Cross-site scripting from local source
33
* @description Writing user input directly to a web page
44
* allows for a cross-site scripting vulnerability.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity recommendation
77
* @precision medium
88
* @id java/xss-local
@@ -13,6 +13,7 @@
1313
import java
1414
import semmle.code.java.dataflow.FlowSources
1515
import semmle.code.java.security.XSS
16+
import DataFlow2::PathGraph
1617

1718
class XSSLocalConfig extends TaintTracking::Configuration2 {
1819
XSSLocalConfig() { this = "XSSLocalConfig" }
@@ -22,6 +23,7 @@ class XSSLocalConfig extends TaintTracking::Configuration2 {
2223
override predicate isSink(DataFlow::Node sink) { sink instanceof XssSink }
2324
}
2425

25-
from XssSink sink, LocalUserInput source, XSSLocalConfig conf
26-
where conf.hasFlow(source, sink)
27-
select sink, "Cross-site scripting vulnerability due to $@.", source, "user-provided value"
26+
from DataFlow2::PathNode source, DataFlow2::PathNode sink, XSSLocalConfig conf
27+
where conf.hasFlowPath(source, sink)
28+
select sink.getNode(), source, sink, "Cross-site scripting vulnerability due to $@.",
29+
source.getNode(), "user-provided value"

0 commit comments

Comments
 (0)