Skip to content

Commit b727fa8

Browse files
committed
add a path sanitizer to zipslip
1 parent 71e7083 commit b727fa8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/ZipSlipCustomizations.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ module ZipSlip {
121121
BasenameSanitizer() { this = DataFlow::moduleImport("path").getAMemberCall("basename") }
122122
}
123123

124+
/**
125+
* An expression that forces the output path to be in the current working folder.
126+
* Recognizes the pattern: `path.join(cwd, path.join('/', orgPath))`.
127+
*/
128+
class PathSanitizer extends Sanitizer, DataFlow::CallNode {
129+
PathSanitizer() {
130+
this = DataFlow::moduleMember("path", "join").getACall() and
131+
exists(DataFlow::CallNode inner | inner = getArgument(1) |
132+
inner = DataFlow::moduleMember("path", "join").getACall() and
133+
inner.getArgument(0).mayHaveStringValue("/")
134+
)
135+
}
136+
}
137+
124138
/**
125139
* Gets a string which is sufficient to exclude to make
126140
* a filepath definitely not refer to parent directories.

0 commit comments

Comments
 (0)