Skip to content

Commit b575195

Browse files
committed
Convert 3 barriers for path injection to MaD
1 parent c94847f commit b575195

File tree

3 files changed

+22
-51
lines changed

3 files changed

+22
-51
lines changed

go/ql/lib/ext/mime.multipart.model.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
extensions:
2+
- addsTo:
3+
pack: codeql/go-all
4+
extensible: barrierModel
5+
data:
6+
# The only way to create a `mime/multipart.FileHeader` is to create a
7+
# `mime/multipart.Form`, which creates the `Filename` field of each
8+
# `mime/multipart.FileHeader` by calling `Part.FileName`, which calls
9+
# `path/filepath.Base` on its return value. In general `path/filepath.Base`
10+
# is not a sanitizer for path traversal, but in this specific case where the
11+
# output is going to be used as a filename rather than a directory name, it
12+
# is adequate.
13+
- ["mime/multipart", "FileHeader", False, "Filename", "", "", "", "path-injection", "manual"]
14+
# `Part.FileName` calls `path/filepath.Base` on its return value. In
15+
# general `path/filepath.Base` is not a sanitizer for path traversal, but in
16+
# this specific case where the output is going to be used as a filename
17+
# rather than a directory name, it is adequate.
18+
- ["mime/multipart", "Part", False, "FileName", "", "", "ReturnValue", "path-injection", "manual"]
219
- addsTo:
320
pack: codeql/go-all
421
extensible: summaryModel

go/ql/lib/ext/path.filepath.model.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
extensions:
2+
- addsTo:
3+
pack: codeql/go-all
4+
extensible: barrierModel
5+
data:
6+
- ["path/filepath", "", False, "Rel", "", "", "ReturnValue", "path-injection", "manual"]
27
- addsTo:
38
pack: codeql/go-all
49
extensible: summaryModel

go/ql/lib/semmle/go/security/TaintedPathCustomizations.qll

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,6 @@ module TaintedPath {
7070
}
7171
}
7272

73-
/**
74-
* A call to `filepath.Rel`, considered as a sanitizer for path traversal.
75-
*/
76-
class FilepathRelSanitizer extends Sanitizer {
77-
FilepathRelSanitizer() {
78-
exists(Function f, FunctionOutput outp |
79-
f.hasQualifiedName("path/filepath", "Rel") and
80-
outp.isResult(0) and
81-
this = outp.getNode(f.getACall())
82-
)
83-
}
84-
}
85-
8673
/**
8774
* A call to `filepath.Clean("/" + e)`, considered to sanitize `e` against path traversal.
8875
*/
@@ -116,44 +103,6 @@ module TaintedPath {
116103
}
117104
}
118105

119-
/**
120-
* A read from the field `Filename` of the type `mime/multipart.FileHeader`,
121-
* considered as a sanitizer for path traversal.
122-
*
123-
* The only way to create a `mime/multipart.FileHeader` is to create a
124-
* `mime/multipart.Form`, which creates the `Filename` field of each
125-
* `mime/multipart.FileHeader` by calling `Part.FileName`, which calls
126-
* `path/filepath.Base` on its return value. In general `path/filepath.Base`
127-
* is not a sanitizer for path traversal, but in this specific case where the
128-
* output is going to be used as a filename rather than a directory name, it
129-
* is adequate.
130-
*/
131-
class MimeMultipartFileHeaderFilenameSanitizer extends Sanitizer {
132-
MimeMultipartFileHeaderFilenameSanitizer() {
133-
this.(DataFlow::FieldReadNode)
134-
.getField()
135-
.hasQualifiedName("mime/multipart", "FileHeader", "Filename")
136-
}
137-
}
138-
139-
/**
140-
* A call to `mime/multipart.Part.FileName`, considered as a sanitizer
141-
* against path traversal.
142-
*
143-
* `Part.FileName` calls `path/filepath.Base` on its return value. In
144-
* general `path/filepath.Base` is not a sanitizer for path traversal, but in
145-
* this specific case where the output is going to be used as a filename
146-
* rather than a directory name, it is adequate.
147-
*/
148-
class MimeMultipartPartFileNameSanitizer extends Sanitizer {
149-
MimeMultipartPartFileNameSanitizer() {
150-
this =
151-
any(Method m | m.hasQualifiedName("mime/multipart", "Part", "FileName"))
152-
.getACall()
153-
.getResult()
154-
}
155-
}
156-
157106
/**
158107
* A check of the form `!strings.Contains(nd, "..")`, considered as a sanitizer guard for
159108
* path traversal.

0 commit comments

Comments
 (0)