|
| 1 | +/** Provides classes and predicates to reason about path injection vulnerabilities. */ |
| 2 | + |
| 3 | +import swift |
| 4 | +private import codeql.swift.dataflow.DataFlow |
| 5 | +private import codeql.swift.dataflow.ExternalFlow |
| 6 | + |
| 7 | +/** A data flow sink for path injection vulnerabilities. */ |
| 8 | +abstract class PathInjectionSink extends DataFlow::Node { } |
| 9 | + |
| 10 | +/** A sanitizer for path injection vulnerabilities. */ |
| 11 | +abstract class PathInjectionSanitizer extends DataFlow::Node { } |
| 12 | + |
| 13 | +/** |
| 14 | + * A unit class for adding additional taint steps. |
| 15 | + * |
| 16 | + * Extend this class to add additional taint steps that should apply to paths related to |
| 17 | + * path injection vulnerabilities. |
| 18 | + */ |
| 19 | +class PathInjectionAdditionalTaintStep extends Unit { |
| 20 | + /** |
| 21 | + * Holds if the step from `node1` to `node2` should be considered a taint |
| 22 | + * step for paths related to path injection vulnerabilities. |
| 23 | + */ |
| 24 | + abstract predicate step(DataFlow::Node node1, DataFlow::Node node2); |
| 25 | +} |
| 26 | + |
| 27 | +private class DefaultPathInjectionSink extends PathInjectionSink { |
| 28 | + DefaultPathInjectionSink() { sinkNode(this, "path-injection") } |
| 29 | +} |
| 30 | + |
| 31 | +private class DefaultPathInjectionSanitizer extends PathInjectionSanitizer { |
| 32 | + DefaultPathInjectionSanitizer() { none() } // TODO: Implement a proper path sanitizer |
| 33 | +} |
| 34 | + |
| 35 | +private class PathInjectionSinks extends SinkModelCsv { |
| 36 | + override predicate row(string row) { |
| 37 | + row = |
| 38 | + [ |
| 39 | + ";Data;true;write(to:options:);;;Argument[0];path-injection", |
| 40 | + ";NSData;true;write(to:atomically:);;;Argument[0];path-injection", |
| 41 | + ";NSData;true;write(to:options:);;;Argument[0];path-injection", |
| 42 | + ";NSData;true;write(toFile:atomically:);;;Argument[0];path-injection", |
| 43 | + ";NSData;true;write(toFile:options:);;;Argument[0];path-injection", |
| 44 | + ";FileManager;true;contentsOfDirectory(at:includingPropertiesForKeys:options:);;;Argument[0];path-injection", |
| 45 | + ";FileManager;true;contentsOfDirectory(atPath:);;;Argument[0];path-injection", |
| 46 | + ";FileManager;true;enumerator(at:includingPropertiesForKeys:options:errorHandler:);;;Argument[0];path-injection", |
| 47 | + ";FileManager;true;enumerator(atPath:);;;Argument[0];path-injection", |
| 48 | + ";FileManager;true;subpathsOfDirectory(atPath:);;;Argument[0];path-injection", |
| 49 | + ";FileManager;true;subpaths(atPath:);;;Argument[0];path-injection", |
| 50 | + ";FileManager;true;createDirectory(at:withIntermediateDirectories:attributes:);;;Argument[0];path-injection", |
| 51 | + ";FileManager;true;createDirectory(atPath:withIntermediateDirectories:attributes:);;;Argument[0];path-injection", |
| 52 | + ";FileManager;true;createFile(atPath:contents:attributes:);;;Argument[0];path-injection", |
| 53 | + ";FileManager;true;removeItem(at:);;;Argument[0];path-injection", |
| 54 | + ";FileManager;true;removeItem(atPath:);;;Argument[0];path-injection", |
| 55 | + ";FileManager;true;trashItem(at:resultingItemURL:);;;Argument[0];path-injection", |
| 56 | + ";FileManager;true;replaceItem(at:withItemAt:backupItemName:options:resultingItemURL:);;;Argument[0..1];path-injection", |
| 57 | + ";FileManager;true;replaceItemAt(_:withItemAt:backupItemName:options:);;;Argument[0..1];path-injection", |
| 58 | + ";FileManager;true;replaceItemAt(_:withItemAt:backupItemName:options:resultingItemURL:);;;Argument[0..1];path-injection", |
| 59 | + ";FileManager;true;copyItem(at:to:);;;Argument[0..1];path-injection", |
| 60 | + ";FileManager;true;copyItem(atPath:toPath:);;;Argument[0..1];path-injection", |
| 61 | + ";FileManager;true;moveItem(at:to:);;;Argument[0..1];path-injection", |
| 62 | + ";FileManager;true;moveItem(atPath:toPath:);;;Argument[0..1];path-injection", |
| 63 | + ";FileManager;true;createSymbolicLink(at:withDestinationURL:);;;Argument[0..1];path-injection", |
| 64 | + ";FileManager;true;createSymbolicLink(atPath:withDestinationPath:);;;Argument[0..1];path-injection", |
| 65 | + ";FileManager;true;linkItem(at:to:);;;Argument[0..1];path-injection", |
| 66 | + ";FileManager;true;linkItem(atPath:toPath:);;;Argument[0..1];path-injection", |
| 67 | + ";FileManager;true;destinationOfSymbolicLink(atPath:);;;Argument[0];path-injection", |
| 68 | + ";FileManager;true;fileExists(atPath:);;;Argument[0];path-injection", |
| 69 | + ";FileManager;true;fileExists(atPath:isDirectory:);;;Argument[0];path-injection", |
| 70 | + ";FileManager;true;isReadableFile(atPath:);;;Argument[0];path-injection", |
| 71 | + ";FileManager;true;isWritableFile(atPath:);;;Argument[0];path-injection", |
| 72 | + ";FileManager;true;isDeletableFile(atPath:);;;Argument[0];path-injection", |
| 73 | + ";FileManager;true;componentsToDisplay(forPath:);;;Argument[0];path-injection", |
| 74 | + ";FileManager;true;displayName(atPath:);;;Argument[0];path-injection", |
| 75 | + ";FileManager;true;attributesOfItem(atPath:);;;Argument[0];path-injection", |
| 76 | + ";FileManager;true;attributesOfFileSystem(forPath:);;;Argument[0];path-injection", |
| 77 | + ";FileManager;true;setAttributes(_:ofItemAtPath:);;;Argument[1];path-injection", |
| 78 | + ";FileManager;true;contents(atPath:);;;Argument[0];path-injection", |
| 79 | + ";FileManager;true;contentsEqual(atPath:andPath:);;;Argument[0..1];path-injection", |
| 80 | + ";FileManager;true;getRelationship(_:ofDirectoryAt:toItemAt:);;;Argument[1..2];path-injection", |
| 81 | + ";FileManager;true;getRelationship(_:of:in:toItemAt:);;;Argument[3];path-injection", |
| 82 | + ";FileManager;true;changeCurrentDirectoryPath(_:);;;Argument[0];path-injection", |
| 83 | + ";FileManager;true;unmountVolume(at:options:completionHandler:);;;Argument[0];path-injection", |
| 84 | + ";FileManager;true;NSHFSTypeOfFile(_:);;;Argument[0];path-injection", |
| 85 | + // Deprecated FileManager methods: |
| 86 | + ";FileManager;true;changeFileAttributes(_:atPath:);;;Argument[1];path-injection", |
| 87 | + ";FileManager;true;fileAttributes(atPath:traverseLink:);;;Argument[0];path-injection", |
| 88 | + ";FileManager;true;fileSystemAttributes(atPath:);;;Argument[0];path-injection", |
| 89 | + ";FileManager;true;directoryContents(atPath:);;;Argument[0];path-injection", |
| 90 | + ";FileManager;true;createDirectory(atPath:attributes:);;;Argument[0];path-injection", |
| 91 | + ";FileManager;true;createSymbolicLink(atPath:pathContent:);;;Argument[0..1];path-injection", |
| 92 | + ";FileManager;true;pathContentOfSymbolicLink(atPath:);;;Argument[0];path-injection", |
| 93 | + ";FileManager;true;replaceItemAtURL(originalItemURL:withItemAtURL:backupItemName:options:);;;Argument[0..1];path-injection", |
| 94 | + ";NIOFileHandle;true;init(descriptor:);;;Argument[0];path-injection", |
| 95 | + ";NIOFileHandle;true;init(path:mode:flags:);;;Argument[0];path-injection", |
| 96 | + ";NIOFileHandle;true;init(path:);;;Argument[0];path-injection" |
| 97 | + ] |
| 98 | + } |
| 99 | +} |
0 commit comments