|
| 1 | +import javascript |
| 2 | +import advanced_security.javascript.frameworks.cap.CDS |
| 3 | + |
| 4 | +/** |
| 5 | + * An access to the `utils` module on a CDS facade. |
| 6 | + */ |
| 7 | +class CdsUtilsModuleAccess extends API::Node { |
| 8 | + CdsUtilsModuleAccess() { exists(CdsFacade cds | this = cds.getMember("utils")) } |
| 9 | +} |
| 10 | + |
| 11 | +/** |
| 12 | + * CDS Utils: |
| 13 | + * `decodeURI`, `decodeURIComponent`, `local` |
| 14 | + */ |
| 15 | +class PathConverters extends DataFlow::CallNode { |
| 16 | + PathConverters() { |
| 17 | + exists(CdsUtilsModuleAccess utils | |
| 18 | + utils.getMember(["decodeURI", "decodeURIComponent", "local"]).getACall() = this |
| 19 | + ) |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Gets the arguments to these calls. |
| 24 | + */ |
| 25 | + DataFlow::Node getPath() { this.getAnArgument() = result } |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * CDS Utils: |
| 30 | + * `isdir`, `isfile` |
| 31 | + */ |
| 32 | +class PathPredicates extends DataFlow::CallNode { |
| 33 | + PathPredicates() { |
| 34 | + exists(CdsUtilsModuleAccess utils | utils.getMember(["isdir", "isfile"]).getACall() = this) |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Gets the arguments to these calls. |
| 39 | + */ |
| 40 | + DataFlow::Node getPath() { this.getAnArgument() = result } |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * CDS Utils: |
| 45 | + * `find`, `stat`, `readdir` |
| 46 | + */ |
| 47 | +class DirectoryReaders extends DataFlow::CallNode { |
| 48 | + DirectoryReaders() { |
| 49 | + exists(CdsUtilsModuleAccess utils | |
| 50 | + utils.getMember(["find", "stat", "readdir"]).getACall() = this |
| 51 | + ) |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Gets the arguments to these calls. |
| 56 | + */ |
| 57 | + DataFlow::Node getPath() { this.getAnArgument() = result } |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * CDS Utils: |
| 62 | + * `mkdirp`, `rmdir`, `rimraf`, `rm` |
| 63 | + */ |
| 64 | +class DirectoryWriters extends DataFlow::CallNode { |
| 65 | + DirectoryWriters() { |
| 66 | + exists(CdsUtilsModuleAccess utils | |
| 67 | + utils.getMember(["mkdirp", "rmdir", "rimraf", "rm"]).getACall() = this |
| 68 | + ) |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Gets the arguments to these calls. |
| 73 | + */ |
| 74 | + DataFlow::Node getPath() { this.getAnArgument() = result } |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * CDS Utils: |
| 79 | + * `read` |
| 80 | + */ |
| 81 | +class FileReaders extends DataFlow::CallNode { |
| 82 | + FileReaders() { exists(CdsUtilsModuleAccess utils | utils.getMember(["read"]).getACall() = this) } |
| 83 | + |
| 84 | + /** |
| 85 | + * Gets the 0th argument to these calls. |
| 86 | + */ |
| 87 | + DataFlow::Node getPath() { this.getArgument(0) = result } |
| 88 | +} |
| 89 | + |
| 90 | +/** |
| 91 | + * CDS Utils: |
| 92 | + * `append`, `write` |
| 93 | + */ |
| 94 | +class FileWriters extends DataFlow::CallNode { |
| 95 | + FileWriters() { |
| 96 | + exists(CdsUtilsModuleAccess utils | utils.getMember(["append", "write"]).getACall() = this) |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Gets the arguments to these calls that represent data. |
| 101 | + */ |
| 102 | + DataFlow::Node getData() { |
| 103 | + this.getNumArgument() = 1 and |
| 104 | + this.getArgument(0) = result |
| 105 | + or |
| 106 | + this.getNumArgument() = 2 and |
| 107 | + this.getArgument(1) = result |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Gets the arguments to these calls that represent a path. |
| 112 | + * Includes arguments to chained calls `to`, where that argument also represents a path. |
| 113 | + */ |
| 114 | + DataFlow::Node getPath() { |
| 115 | + this.getAMemberCall("to").getAnArgument() = result |
| 116 | + or |
| 117 | + this.getNumArgument() = 2 and |
| 118 | + this.getArgument(0) = result |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +/** |
| 123 | + * CDS Utils: |
| 124 | + * `copy` |
| 125 | + */ |
| 126 | +class FileReaderWriters extends DataFlow::CallNode { |
| 127 | + FileReaderWriters() { |
| 128 | + exists(CdsUtilsModuleAccess utils | utils.getMember(["copy"]).getACall() = this) |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Gets the arguments to these calls that represent a path from which data is read. |
| 133 | + */ |
| 134 | + DataFlow::Node getFromPath() { this.getArgument(0) = result } |
| 135 | + |
| 136 | + /** |
| 137 | + * Gets the arguments to these calls that represent a path to which data is written. |
| 138 | + * Includes arguments to chained calls `to`, where that argument also represents a path. |
| 139 | + */ |
| 140 | + DataFlow::Node getToPath() { |
| 141 | + this.getAMemberCall("to").getArgument(_) = result |
| 142 | + or |
| 143 | + this.getArgument(1) = result |
| 144 | + } |
| 145 | +} |
0 commit comments