6
6
import go
7
7
import semmle.go.dataflow.barrierguardutil.RegexpCheck
8
8
import DataFlow
9
+
9
10
/**
10
11
* Provides extension points for customizing the taint tracking configuration for reasoning about
11
12
* path-traversal vulnerabilities.
@@ -79,15 +80,15 @@ module TaintedPath {
79
80
class FilepathCleanSanitizer extends Sanitizer {
80
81
FilepathCleanSanitizer ( ) {
81
82
exists ( DataFlow:: CallNode cleanCall , StringOps:: Concatenation concatNode |
82
- cleanCall =
83
- any ( Function f | f .hasQualifiedName ( "path/filepath" , "Clean" ) ) .getACall ( ) and
83
+ cleanCall = any ( Function f | f .hasQualifiedName ( "path/filepath" , "Clean" ) ) .getACall ( ) and
84
84
concatNode = cleanCall .getArgument ( 0 ) and
85
85
concatNode .getOperand ( 0 ) .asExpr ( ) .( StringLit ) .getValue ( ) = "/" and
86
86
this = cleanCall .getResult ( )
87
87
)
88
88
}
89
89
}
90
- /**
90
+
91
+ /**
91
92
* A call to `filepath.Base(e)`, considered to sanitize `e` against path traversal.
92
93
*/
93
94
class FilepathBaseSanitizer extends Sanitizer {
@@ -107,8 +108,8 @@ module TaintedPath {
107
108
frn .getField ( ) .hasQualifiedName ( "mime/multipart" , "FileHeader" , "Filename" ) and
108
109
this = frn
109
110
)
110
- }
111
111
}
112
+ }
112
113
113
114
/**
114
115
* A check of the form `!strings.Contains(nd, "..")`, considered as a sanitizer guard for
@@ -127,15 +128,15 @@ module TaintedPath {
127
128
branch = false
128
129
}
129
130
}
130
- /**
131
+
132
+ /**
131
133
* A replacement of the form `!strings.ReplaceAll(nd, "..")` or `!strings.ReplaceAll(nd, ".")`, considered as a sanitizer for
132
134
* path traversal.
133
135
*/
134
136
class DotDotReplace extends Sanitizer {
135
137
DotDotReplace ( ) {
136
138
exists ( DataFlow:: CallNode cleanCall , DataFlow:: Node valueNode |
137
- cleanCall =
138
- any ( Function f | f .hasQualifiedName ( "strings" , "ReplaceAll" ) ) .getACall ( ) and
139
+ cleanCall = any ( Function f | f .hasQualifiedName ( "strings" , "ReplaceAll" ) ) .getACall ( ) and
139
140
valueNode = cleanCall .getArgument ( 1 ) and
140
141
valueNode .asExpr ( ) .( StringLit ) .getValue ( ) = [ ".." , "." ] and
141
142
this = cleanCall .getResult ( )
0 commit comments