Skip to content

Commit 3f26250

Browse files
committed
Swift: Remove the sources instead (more general solution).
1 parent 2b7b1c6 commit 3f26250

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/FileManager.qll

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ private import codeql.swift.dataflow.ExternalFlow
77

88
/**
99
* A model for `FileManager` members that are flow sources.
10+
*
11+
* Note that functions returning paths on the file system have been removed
12+
* from this model. Though they are in principle tainted by the data on the
13+
* local filesystem, in practice we've found results from them almost always
14+
* have little value.
1015
*/
1116
private class FileManagerSource extends SourceModelCsv {
1217
override predicate row(string row) {
1318
row =
1419
[
15-
";FileManager;true;contentsOfDirectory(at:includingPropertiesForKeys:options:);;;ReturnValue;local",
16-
";FileManager;true;contentsOfDirectory(atPath:);;;ReturnValue;local",
17-
";FileManager;true;directoryContents(atPath:);;;ReturnValue;local",
18-
";FileManager;true;subpathsOfDirectory(atPath:);;;ReturnValue;local",
19-
";FileManager;true;subpaths(atPath:);;;ReturnValue;local",
20-
";FileManager;true;destinationOfSymbolicLink(atPath:);;;ReturnValue;local",
21-
";FileManager;true;pathContentOfSymbolicLink(atPath:);;;ReturnValue;local",
20+
//";FileManager;true;contentsOfDirectory(at:includingPropertiesForKeys:options:);;;ReturnValue;local",
21+
//";FileManager;true;contentsOfDirectory(atPath:);;;ReturnValue;local",
22+
//";FileManager;true;directoryContents(atPath:);;;ReturnValue;local",
23+
//";FileManager;true;subpathsOfDirectory(atPath:);;;ReturnValue;local",
24+
//";FileManager;true;subpaths(atPath:);;;ReturnValue;local",
25+
//";FileManager;true;destinationOfSymbolicLink(atPath:);;;ReturnValue;local",
26+
//";FileManager;true;pathContentOfSymbolicLink(atPath:);;;ReturnValue;local",
2227
";FileManager;true;contents(atPath:);;;ReturnValue;local"
2328
]
2429
}

swift/ql/lib/codeql/swift/security/CommandInjectionExtensions.qll

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,5 @@ private class CommandInjectionDefaultBarrier extends CommandInjectionBarrier {
6464
CommandInjectionDefaultBarrier() {
6565
// any numeric type
6666
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() = "Numeric"
67-
or
68-
// we get poor results when the tainted data is a directory list, such as
69-
// the result of `FileMananger.contentsOfDirectory` and similar functions.
70-
exists(CallExpr ce |
71-
ce.getStaticTarget().getName().matches(["%directory%", "%Directory%"]) and
72-
this.asExpr() = ce
73-
)
7467
}
7568
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
failures
21
testFailures
2+
failures

swift/ql/test/library-tests/dataflow/flowsources/filemanager.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class FileManager : NSObject {
3434
func testFileHandle(fm: FileManager, url: URL, path: String) {
3535
do
3636
{
37-
let contents1 = try fm.contentsOfDirectory(at: url, includingPropertiesForKeys: nil) // $ source=local
38-
let contents2 = try fm.contentsOfDirectory(atPath: path) // $ source=local
39-
let contents3 = fm.directoryContents(atPath: path)! // $ source=local
37+
let contents1 = try fm.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
38+
let contents2 = try fm.contentsOfDirectory(atPath: path)
39+
let contents3 = fm.directoryContents(atPath: path)!
4040

41-
let subpaths1 = try fm.subpathsOfDirectory(atPath: path) // $ source=local
42-
let subpaths2 = fm.subpaths(atPath: path)! // $ source=local
41+
let subpaths1 = try fm.subpathsOfDirectory(atPath: path)
42+
let subpaths2 = fm.subpaths(atPath: path)!
4343

44-
let link1 = try fm.destinationOfSymbolicLink(atPath: path) // $ source=local
45-
let link2 = fm.pathContentOfSymbolicLink(atPath: path)! // $ source=local
44+
let link1 = try fm.destinationOfSymbolicLink(atPath: path)
45+
let link2 = fm.pathContentOfSymbolicLink(atPath: path)!
4646

4747
let data = fm.contents(atPath: path)! // $ source=local
4848
} catch {

0 commit comments

Comments
 (0)