Skip to content

Commit 626127b

Browse files
authored
Merge pull request #312 from microsoft/fix-merge-conflict-inTaintedPathQuery-2
C#: Fix an incorrect merge conflict resolution.
2 parents 676c6b2 + f9e1165 commit 626127b

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

csharp/ql/lib/semmle/code/csharp/security/dataflow/TaintedPathQuery.qll

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,6 @@ private class GetFullPathStep extends PathNormalizationStep {
5252
}
5353
}
5454

55-
/** Holds if `e` may evaluate to an absolute path. */
56-
bindingset[e]
57-
pragma[inline_late]
58-
private predicate isAbsolute(Expr e) {
59-
exists(Expr absolute | DataFlow::localExprFlow(absolute, e) |
60-
exists(Call call | absolute = call |
61-
call.getARuntimeTarget()
62-
.hasFullyQualifiedName(["System.Web.HttpServerUtilityBase", "System.Web.HttpRequest"],
63-
"MapPath")
64-
or
65-
call.getARuntimeTarget().hasFullyQualifiedName("System.IO.Path", "GetFullPath")
66-
or
67-
call.getARuntimeTarget().hasFullyQualifiedName("System.IO.Directory", "GetCurrentDirectory")
68-
)
69-
or
70-
exists(PropertyRead read | absolute = read |
71-
read.getTarget().hasFullyQualifiedName("System", "Environment", "CurrentDirectory")
72-
)
73-
)
74-
}
75-
76-
private class PathCombineStep extends PathNormalizationStep {
77-
override predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) {
78-
exists(Call call |
79-
// The result of `Path.Combine(x, y)` is an absolute path when `x` is an
80-
// absolute path.
81-
call.getARuntimeTarget().hasFullyQualifiedName("System.IO.Path", "Combine") and
82-
isAbsolute(call.getArgument(0)) and
83-
n1.asExpr() = call.getArgument(1) and
84-
n2.asExpr() = call
85-
)
86-
}
87-
}
88-
8955
/**
9056
* A taint-tracking configuration for uncontrolled data in path expression vulnerabilities.
9157
*/
@@ -108,12 +74,12 @@ private module TaintedPathConfig implements DataFlow::StateConfigSig {
10874
s2 = Normalized()
10975
}
11076

77+
predicate isBarrier(DataFlow::Node node, FlowState state) { node.(Sanitizer).isBarrier(state) }
78+
11179
predicate isBarrierOut(DataFlow::Node node, FlowState state) {
11280
isAdditionalFlowStep(_, state, node, _)
11381
}
11482

115-
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
116-
11783
predicate observeDiffInformedIncrementalMode() { any() }
11884
}
11985

csharp/ql/test/query-tests/Security Features/CWE-022/TaintedPath/TaintedPath.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ public void ProcessRequest(HttpContext ctx)
6868
string absolutePath = ctx.Request.MapPath("~MyTempFile");
6969
string fullPath2 = Path.Combine(absolutePath, path);
7070
if (fullPath2.StartsWith(absolutePath + Path.DirectorySeparatorChar)) {
71-
File.ReadAllText(fullPath2); // GOOD
71+
File.ReadAllText(fullPath2); // BAD
72+
}
73+
74+
string normalizedFullPath2 = Path.GetFullPath(fullPath2);
75+
if (normalizedFullPath2.StartsWith(absolutePath + Path.DirectorySeparatorChar)) {
76+
File.ReadAllText(normalizedFullPath2); // GOOD
7277
}
7378
}
7479

csharp/ql/test/query-tests/Security Features/CWE-022/TaintedPath/TaintedPath.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| TaintedPath.cs:38:49:38:55 | access to local variable badPath | TaintedPath.cs:10:23:10:45 | access to property QueryString : NameValueCollection | TaintedPath.cs:38:49:38:55 | access to local variable badPath | This path depends on a $@. | TaintedPath.cs:10:23:10:45 | access to property QueryString | user-provided value |
88
| TaintedPath.cs:51:26:51:29 | access to local variable path | TaintedPath.cs:10:23:10:45 | access to property QueryString : NameValueCollection | TaintedPath.cs:51:26:51:29 | access to local variable path | This path depends on a $@. | TaintedPath.cs:10:23:10:45 | access to property QueryString | user-provided value |
99
| TaintedPath.cs:66:45:66:48 | access to local variable path | TaintedPath.cs:10:23:10:45 | access to property QueryString : NameValueCollection | TaintedPath.cs:66:45:66:48 | access to local variable path | This path depends on a $@. | TaintedPath.cs:10:23:10:45 | access to property QueryString | user-provided value |
10+
| TaintedPath.cs:71:30:71:38 | access to local variable fullPath2 | TaintedPath.cs:10:23:10:45 | access to property QueryString : NameValueCollection | TaintedPath.cs:71:30:71:38 | access to local variable fullPath2 | This path depends on a $@. | TaintedPath.cs:10:23:10:45 | access to property QueryString | user-provided value |
1011
edges
1112
| TaintedPath.cs:10:16:10:19 | access to local variable path : String | TaintedPath.cs:12:50:12:53 | access to local variable path | provenance | |
1213
| TaintedPath.cs:10:16:10:19 | access to local variable path : String | TaintedPath.cs:17:51:17:54 | access to local variable path | provenance | |
@@ -21,8 +22,13 @@ edges
2122
| TaintedPath.cs:35:16:35:22 | access to local variable badPath : String | TaintedPath.cs:36:25:36:31 | access to local variable badPath | provenance | |
2223
| TaintedPath.cs:35:16:35:22 | access to local variable badPath : String | TaintedPath.cs:38:49:38:55 | access to local variable badPath | provenance | |
2324
| TaintedPath.cs:59:44:59:47 | access to local variable path : String | TaintedPath.cs:66:45:66:48 | access to local variable path | provenance | |
25+
| TaintedPath.cs:59:44:59:47 | access to local variable path : String | TaintedPath.cs:69:55:69:58 | access to local variable path : String | provenance | |
26+
| TaintedPath.cs:69:16:69:24 | access to local variable fullPath2 : String | TaintedPath.cs:71:30:71:38 | access to local variable fullPath2 | provenance | |
27+
| TaintedPath.cs:69:28:69:59 | call to method Combine : String | TaintedPath.cs:69:16:69:24 | access to local variable fullPath2 : String | provenance | |
28+
| TaintedPath.cs:69:55:69:58 | access to local variable path : String | TaintedPath.cs:69:28:69:59 | call to method Combine : String | provenance | MaD:2 |
2429
models
2530
| 1 | Summary: System.Collections.Specialized; NameValueCollection; false; get_Item; (System.String); ; Argument[this]; ReturnValue; taint; df-generated |
31+
| 2 | Summary: System.IO; Path; false; Combine; (System.String,System.String); ; Argument[1]; ReturnValue; taint; manual |
2632
nodes
2733
| TaintedPath.cs:10:16:10:19 | access to local variable path : String | semmle.label | access to local variable path : String |
2834
| TaintedPath.cs:10:23:10:45 | access to property QueryString : NameValueCollection | semmle.label | access to property QueryString : NameValueCollection |
@@ -37,4 +43,8 @@ nodes
3743
| TaintedPath.cs:51:26:51:29 | access to local variable path | semmle.label | access to local variable path |
3844
| TaintedPath.cs:59:44:59:47 | access to local variable path : String | semmle.label | access to local variable path : String |
3945
| TaintedPath.cs:66:45:66:48 | access to local variable path | semmle.label | access to local variable path |
46+
| TaintedPath.cs:69:16:69:24 | access to local variable fullPath2 : String | semmle.label | access to local variable fullPath2 : String |
47+
| TaintedPath.cs:69:28:69:59 | call to method Combine : String | semmle.label | call to method Combine : String |
48+
| TaintedPath.cs:69:55:69:58 | access to local variable path : String | semmle.label | access to local variable path : String |
49+
| TaintedPath.cs:71:30:71:38 | access to local variable fullPath2 | semmle.label | access to local variable fullPath2 |
4050
subpaths

0 commit comments

Comments
 (0)