Skip to content

Commit 77213aa

Browse files
authored
Merge pull request #462 from xiemaisi/js/security-paths
Approved by esben-semmle
2 parents a066749 + 4112af5 commit 77213aa

File tree

65 files changed

+2694
-654
lines changed

Some content is hidden

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

65 files changed

+2694
-654
lines changed

change-notes/1.19/analysis-javascript.md

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

1414
* Type inference for function calls has been improved. This may give additional results for queries that rely on type inference.
1515

16+
* Where applicable, path explanations have been added to the security queries.
17+
1618
## New queries
1719

1820
| **Query** | **Tags** | **Purpose** |

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Uncontrolled data used in path expression
33
* @description Accessing paths influenced by users can allow an attacker to access
44
* unexpected resources.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id js/path-injection
@@ -15,9 +15,10 @@
1515
*/
1616

1717
import javascript
18-
import semmle.javascript.security.dataflow.RemoteFlowSources
1918
import semmle.javascript.security.dataflow.TaintedPath::TaintedPath
19+
import DataFlow::PathGraph
2020

21-
from Configuration cfg, DataFlow::Node source, DataFlow::Node sink
22-
where cfg.hasFlow(source, sink)
23-
select sink, "This path depends on $@.", source, "a user-provided value"
21+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
22+
where cfg.hasPathFlow(source, sink)
23+
select sink.getNode(), source, sink, "This path depends on $@.",
24+
source.getNode(), "a user-provided value"

javascript/ql/src/Security/CWE-078/CommandInjection.ql

Lines changed: 9 additions & 7 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 may allow a malicious
44
* user to change the meaning of the command.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id js/command-line-injection
@@ -14,11 +14,13 @@
1414

1515
import javascript
1616
import semmle.javascript.security.dataflow.CommandInjection::CommandInjection
17+
import DataFlow::PathGraph
1718

18-
from Configuration cfg, DataFlow::Node source, DataFlow::Node sink, DataFlow::Node highlight
19-
where cfg.hasFlow(source, sink) and
20-
if cfg.isSinkWithHighlight(sink, _) then
21-
cfg.isSinkWithHighlight(sink, highlight)
19+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, DataFlow::Node highlight
20+
where cfg.hasPathFlow(source, sink) and
21+
if cfg.isSinkWithHighlight(sink.getNode(), _) then
22+
cfg.isSinkWithHighlight(sink.getNode(), highlight)
2223
else
23-
highlight = sink
24-
select highlight, "This command depends on $@.", source, "a user-provided value"
24+
highlight = sink.getNode()
25+
select highlight, source, sink, "This command depends on $@.",
26+
source.getNode(), "a user-provided value"

javascript/ql/src/Security/CWE-079/ReflectedXss.ql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Reflected cross-site scripting
33
* @description Writing user input directly to an HTTP response allows for
44
* a cross-site scripting vulnerability.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id js/reflected-xss
@@ -13,8 +13,9 @@
1313

1414
import javascript
1515
import semmle.javascript.security.dataflow.ReflectedXss::ReflectedXss
16+
import DataFlow::PathGraph
1617

17-
from Configuration xss, DataFlow::Node source, DataFlow::Node sink
18-
where xss.hasFlow(source, sink)
19-
select sink, "Cross-site scripting vulnerability due to $@.",
20-
source, "user-provided value"
18+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
19+
where cfg.hasPathFlow(source, sink)
20+
select sink.getNode(), source, sink, "Cross-site scripting vulnerability due to $@.",
21+
source.getNode(), "user-provided value"

javascript/ql/src/Security/CWE-079/StoredXss.ql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Stored cross-site scripting
33
* @description Using uncontrolled stored values in HTML allows for
44
* a stored cross-site scripting vulnerability.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id js/stored-xss
@@ -13,8 +13,9 @@
1313

1414
import javascript
1515
import semmle.javascript.security.dataflow.StoredXss::StoredXss
16+
import DataFlow::PathGraph
1617

17-
from Configuration xss, DataFlow::Node source, DataFlow::Node sink
18-
where xss.hasFlow(source, sink)
19-
select sink, "Stored cross-site scripting vulnerability due to $@.",
20-
source, "stored value"
18+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
19+
where cfg.hasPathFlow(source, sink)
20+
select sink.getNode(), source, sink, "Stored cross-site scripting vulnerability due to $@.",
21+
source.getNode(), "stored value"

javascript/ql/src/Security/CWE-079/Xss.ql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Client side cross-site scripting
33
* @description Writing user input directly to the DOM allows for
44
* a cross-site scripting vulnerability.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id js/xss
@@ -13,8 +13,9 @@
1313

1414
import javascript
1515
import semmle.javascript.security.dataflow.DomBasedXss::DomBasedXss
16+
import DataFlow::PathGraph
1617

17-
from Configuration xss, DataFlow::Node source, Sink sink
18-
where xss.hasFlow(source, sink)
19-
select sink, sink.getVulnerabilityKind() + " vulnerability due to $@.",
20-
source, "user-provided value"
18+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
19+
where cfg.hasPathFlow(source, sink)
20+
select sink.getNode(), source, sink, sink.getNode().(Sink).getVulnerabilityKind() + " vulnerability due to $@.",
21+
source.getNode(), "user-provided value"

javascript/ql/src/Security/CWE-089/SqlInjection.ql

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Database query built from user-controlled sources
33
* @description Building a database query from user-controlled sources is vulnerable to insertion of
44
* malicious code by the user.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id js/sql-injection
@@ -13,16 +13,11 @@
1313
import javascript
1414
import semmle.javascript.security.dataflow.SqlInjection
1515
import semmle.javascript.security.dataflow.NosqlInjection
16+
import DataFlow::PathGraph
1617

17-
predicate sqlInjection(DataFlow::Node source, DataFlow::Node sink) {
18-
any(SqlInjection::Configuration cfg).hasFlow(source, sink)
19-
}
20-
21-
predicate nosqlInjection(DataFlow::Node source, DataFlow::Node sink) {
22-
any(NosqlInjection::Configuration cfg).hasFlow(source, sink)
23-
}
24-
25-
from DataFlow::Node source, DataFlow::Node sink
26-
where sqlInjection(source, sink) or
27-
nosqlInjection(source, sink)
28-
select sink, "This query depends on $@.", source, "a user-provided value"
18+
from DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
19+
where (cfg instanceof SqlInjection::Configuration or
20+
cfg instanceof NosqlInjection::Configuration) and
21+
cfg.hasPathFlow(source, sink)
22+
select sink.getNode(), source, sink, "This query depends on $@.",
23+
source.getNode(), "a user-provided value"

javascript/ql/src/Security/CWE-094/CodeInjection.ql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @name Code injection
33
* @description Interpreting unsanitized user input as code allows a malicious user arbitrary
44
* code execution.
5-
* @kind problem
5+
* @kind path-problem
66
* @problem.severity error
77
* @precision high
88
* @id js/code-injection
@@ -14,7 +14,9 @@
1414

1515
import javascript
1616
import semmle.javascript.security.dataflow.CodeInjection::CodeInjection
17+
import DataFlow::PathGraph
1718

18-
from Configuration codeInjection, DataFlow::Node source, DataFlow::Node sink
19-
where codeInjection.hasFlow(source, sink)
20-
select sink, "$@ flows to here and is interpreted as code.", source, "User-provided value"
19+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
20+
where cfg.hasPathFlow(source, sink)
21+
select sink.getNode(), source, sink, "$@ flows to here and is interpreted as code.",
22+
source.getNode(), "User-provided value"
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Use of externally-controlled format string
33
* @description Using external input in format strings can lead to garbled output.
4-
* @kind problem
4+
* @kind path-problem
55
* @problem.severity warning
66
* @precision high
77
* @id js/tainted-format-string
@@ -11,7 +11,9 @@
1111

1212
import javascript
1313
import semmle.javascript.security.dataflow.TaintedFormatString::TaintedFormatString
14+
import DataFlow::PathGraph
1415

15-
from Configuration c, DataFlow::Node source, DataFlow::Node sink
16-
where c.hasFlow(source, sink)
17-
select sink, "$@ flows here and is used in a format string.", source, "User-provided value"
16+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
17+
where cfg.hasPathFlow(source, sink)
18+
select sink.getNode(), source, sink, "$@ flows here and is used in a format string.",
19+
source.getNode(), "User-provided value"
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/**
22
* @name File data in outbound network request
33
* @description Directly sending file data in an outbound network request can indicate unauthorized information disclosure.
4-
* @kind problem
4+
* @kind path-problem
55
* @problem.severity warning
66
* @id js/file-access-to-http
77
* @tags security
88
* external/cwe/cwe-200
99
*/
1010

1111
import javascript
12-
import semmle.javascript.security.dataflow.FileAccessToHttp
12+
import semmle.javascript.security.dataflow.FileAccessToHttp::FileAccessToHttp
13+
import DataFlow::PathGraph
1314

14-
from FileAccessToHttp::Configuration config, DataFlow::Node src, DataFlow::Node sink
15-
where config.hasFlow (src, sink)
16-
select sink, "$@ flows directly to outbound network request", src, "File data"
15+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
16+
where cfg.hasPathFlow(source, sink)
17+
select sink.getNode(), source, sink, "$@ flows directly to outbound network request",
18+
source.getNode(), "File data"

0 commit comments

Comments
 (0)