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

Skip to content

Commit 09b2387

Browse files
committed
C#: ZipSlip, introduce source, sink, sanitizer classes.
1 parent 3bc035f commit 09b2387

1 file changed

Lines changed: 48 additions & 32 deletions

File tree

  • csharp/ql/src/semmle/code/csharp/security/dataflow

csharp/ql/src/semmle/code/csharp/security/dataflow/ZipSlip.qll

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,54 @@
44
import csharp
55

66
module ZipSlip {
7+
8+
/**
9+
* A data flow source for unsafe zip extraction.
10+
*/
11+
abstract class Source extends DataFlow::Node { }
12+
13+
/**
14+
* A data flow sink for unsafe zip extraction.
15+
*/
16+
abstract class Sink extends DataFlow::ExprNode { }
17+
18+
/**
19+
* A sanitizer for unsafe zipe extraction.
20+
*/
21+
abstract class Sanitizer extends DataFlow::ExprNode { }
22+
23+
/** A taint tracking configuration for ZipSlip */
24+
class ZipSlipTaintTrackingConfiguration extends TaintTracking::Configuration {
25+
ZipSlipTaintTrackingConfiguration() {
26+
this = "ZipSlipTaintTracking"
27+
}
28+
29+
override predicate isSource(DataFlow::Node source) {
30+
exists(PropertyAccess pa |
31+
source.asExpr() = archiveFullName(pa)
32+
)
33+
}
34+
35+
override predicate isSink(DataFlow::Node sink) {
36+
exists(MethodCall mc |
37+
sink.asExpr() = compressionExtractToFileArgument(mc) or
38+
sink.asExpr() = fileOpenArgument(mc)
39+
)
40+
or
41+
exists(ObjectCreation oc |
42+
sink.asExpr() = streamConstructorArgument(oc) or
43+
sink.asExpr() = fileInfoConstructorArgument(oc)
44+
)
45+
}
46+
47+
override predicate isSanitizer(DataFlow::Node node) {
48+
exists(MethodCall mc |
49+
node.asExpr() = fileNameExtraction(mc) or
50+
node.asExpr() = stringCheck(mc)
51+
)
52+
}
53+
}
54+
755
// access to full name of the archive item
856
Expr archiveFullName(PropertyAccess pa) {
957
pa.getTarget().getDeclaringType().hasQualifiedName("System.IO.Compression.ZipArchiveEntry") and
@@ -52,36 +100,4 @@ module ZipSlip {
52100
) and
53101
result = mc.getQualifier()
54102
}
55-
56-
// Taint tracking configuration for ZipSlip
57-
class ZipSlipTaintTrackingConfiguration extends TaintTracking::Configuration {
58-
ZipSlipTaintTrackingConfiguration() {
59-
this = "ZipSlipTaintTracking"
60-
}
61-
62-
override predicate isSource(DataFlow::Node source) {
63-
exists(PropertyAccess pa |
64-
source.asExpr() = archiveFullName(pa)
65-
)
66-
}
67-
68-
override predicate isSink(DataFlow::Node sink) {
69-
exists(MethodCall mc |
70-
sink.asExpr() = compressionExtractToFileArgument(mc) or
71-
sink.asExpr() = fileOpenArgument(mc)
72-
)
73-
or
74-
exists(ObjectCreation oc |
75-
sink.asExpr() = streamConstructorArgument(oc) or
76-
sink.asExpr() = fileInfoConstructorArgument(oc)
77-
)
78-
}
79-
80-
override predicate isSanitizer(DataFlow::Node node) {
81-
exists(MethodCall mc |
82-
node.asExpr() = fileNameExtraction(mc) or
83-
node.asExpr() = stringCheck(mc)
84-
)
85-
}
86-
}
87103
}

0 commit comments

Comments
 (0)