Skip to content

Commit fc925d4

Browse files
committed
C#: ZipSlip - Treat the result of Substring as sanitized.
As with the previous commit, this considers the result of substring as sanitized, rather than the argument.
1 parent 43d7e59 commit fc925d4

File tree

1 file changed

+19
-5
lines changed
  • csharp/ql/src/semmle/code/csharp/security/dataflow

1 file changed

+19
-5
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module ZipSlip {
9696
}
9797

9898
/**
99-
* An argument to `GetFileName`.
99+
* An call to `GetFileName`.
100100
*
101101
* This is considered a sanitizer because it extracts just the file name, not the full path.
102102
*/
@@ -110,16 +110,30 @@ module ZipSlip {
110110
}
111111

112112
/**
113-
* A qualifier in a call to `StartsWith` or `Substring` string method.
113+
* A call to Substring.
114114
*
115-
* A call to a String method such as `StartsWith` or `Substring` can indicate a check for a
115+
* This is considered a sanitizer because `Substring` may be used to extract a single component
116+
* of a path to avoid ZipSlip.
117+
*/
118+
class SubstringSanitizer extends Sanitizer {
119+
SubstringSanitizer() {
120+
exists(MethodCall mc |
121+
mc.getTarget().hasQualifiedName("System.String", "Substring") |
122+
this.asExpr() = mc
123+
)
124+
}
125+
}
126+
127+
/**
128+
* A qualifier in a call to `StartsWith` string method.
129+
*
130+
* A call to a String method such as `StartsWith` can indicate a check for a
116131
* relative path, or a check against the destination folder for whitelisted/target path, etc.
117132
*/
118133
class StringCheckSanitizer extends Sanitizer {
119134
StringCheckSanitizer() {
120135
exists(MethodCall mc |
121-
mc.getTarget().hasQualifiedName("System.String", "StartsWith") or
122-
mc.getTarget().hasQualifiedName("System.String", "Substring") |
136+
mc.getTarget().hasQualifiedName("System.String", "StartsWith") |
123137
this.asExpr() = mc.getQualifier()
124138
)
125139
}

0 commit comments

Comments
 (0)