Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be71ddf

Browse files
committed
introduce basic BuildArtifactLeak query
1 parent 896a9b0 commit be71ddf

4 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<include src="CleartextStorage.qhelp" /></qhelp>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @name Storage of sensitive information in build artifact
3+
* @description Including sensitive information in a build artifact can
4+
* expose it to an attacker.
5+
* @kind path-problem
6+
* @problem.severity error
7+
* @precision high
8+
* @id js/build-artifact-leak
9+
* @tags security
10+
* external/cwe/cwe-312
11+
* external/cwe/cwe-315
12+
* external/cwe/cwe-359
13+
*/
14+
15+
import javascript
16+
import semmle.javascript.security.dataflow.BuildArtifactLeak::BuildArtifactLeak
17+
import DataFlow::PathGraph
18+
19+
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
20+
where cfg.hasFlowPath(source, sink)
21+
select sink.getNode(), source, sink,
22+
"Sensitive data returned by $@ is stored in build artifact here.", source.getNode(),
23+
source.getNode().(CleartextLogging::Source).describe()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Provides a dataflow tracking configuration for reasoning about
3+
* storage of sensitive information in build artifact.
4+
*
5+
* Note, for performance reasons: only import this file if
6+
* `CleartextLogging::Configuration` is needed, otherwise
7+
* `CleartextLoggingCustomizations` should be imported instead.
8+
*/
9+
10+
import javascript
11+
12+
module BuildArtifactLeak {
13+
import BuildArtifactLeakCustomizations::BuildArtifactLeak
14+
import CleartextLoggingCustomizations::CleartextLogging as CleartextLogging
15+
16+
/**
17+
* A taint tracking configuration for storage of sensitive information in build artifact.
18+
*/
19+
class Configuration extends TaintTracking::Configuration {
20+
Configuration() { this = "CleartextLogging" }
21+
22+
override predicate isSource(DataFlow::Node source, DataFlow::FlowLabel lbl) {
23+
source.(CleartextLogging::Source).getLabel() = lbl
24+
}
25+
26+
override predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel lbl) {
27+
sink.(Sink).getLabel() = lbl
28+
}
29+
30+
override predicate isSanitizer(DataFlow::Node node) { node instanceof CleartextLogging::Barrier }
31+
32+
override predicate isSanitizerEdge(DataFlow::Node pred, DataFlow::Node succ) {
33+
CleartextLogging::isSanitizerEdge(pred, succ)
34+
}
35+
36+
override predicate isAdditionalTaintStep(DataFlow::Node src, DataFlow::Node trg) {
37+
CleartextLogging::isAdditionalTaintStep(src, trg)
38+
}
39+
}
40+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Provides default sources, sinks and sanitizers for reasoning about
3+
* storage of sensitive information in build artifact, as well as extension
4+
* points for adding your own.
5+
*/
6+
7+
import javascript
8+
private import semmle.javascript.dataflow.InferredTypes
9+
private import semmle.javascript.security.SensitiveActions::HeuristicNames
10+
11+
module BuildArtifactLeak {
12+
/**
13+
* A data flow sink for clear-text logging of sensitive information.
14+
*/
15+
abstract class Sink extends DataFlow::Node {
16+
DataFlow::FlowLabel getLabel() { result.isTaint() }
17+
}
18+
19+
/**
20+
* An instantiation of `webpack.DefintePlugin` that stores information in a compiled JavaScript file.
21+
*/
22+
class WebpackDefinePluginSink extends Sink {
23+
WebpackDefinePluginSink() {
24+
this =
25+
DataFlow::moduleMember("webpack", "DefinePlugin")
26+
.getAnInstantiation()
27+
.getAnArgument()
28+
.getALocalSource()
29+
.getAPropertySource()
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)