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.
@@ -96,15 +97,15 @@ module TaintedPath {
96
97
class FilepathCleanSanitizer extends Sanitizer {
97
98
FilepathCleanSanitizer ( ) {
98
99
exists ( DataFlow:: CallNode cleanCall , StringOps:: Concatenation concatNode |
99
- cleanCall =
100
- any ( Function f | f .hasQualifiedName ( "path/filepath" , "Clean" ) ) .getACall ( ) and
100
+ cleanCall = any ( Function f | f .hasQualifiedName ( "path/filepath" , "Clean" ) ) .getACall ( ) and
101
101
concatNode = cleanCall .getArgument ( 0 ) and
102
102
concatNode .getOperand ( 0 ) .asExpr ( ) .( StringLit ) .getValue ( ) = "/" and
103
103
this = cleanCall .getResult ( )
104
104
)
105
105
}
106
106
}
107
- /**
107
+
108
+ /**
108
109
* A call to `filepath.Base(e)`, considered to sanitize `e` against path traversal.
109
110
*/
110
111
class FilepathBaseSanitizer extends Sanitizer {
@@ -124,8 +125,8 @@ module TaintedPath {
124
125
frn .getField ( ) .hasQualifiedName ( "mime/multipart" , "FileHeader" , "Filename" ) and
125
126
this = frn
126
127
)
127
- }
128
128
}
129
+ }
129
130
130
131
/**
131
132
* A check of the form `!strings.Contains(nd, "..")`, considered as a sanitizer guard for
@@ -144,15 +145,15 @@ module TaintedPath {
144
145
branch = false
145
146
}
146
147
}
147
- /**
148
+
149
+ /**
148
150
* A replacement of the form `!strings.ReplaceAll(nd, "..")` or `!strings.ReplaceAll(nd, ".")`, considered as a sanitizer for
149
151
* path traversal.
150
152
*/
151
153
class DotDotReplace extends Sanitizer {
152
154
DotDotReplace ( ) {
153
155
exists ( DataFlow:: CallNode cleanCall , DataFlow:: Node valueNode |
154
- cleanCall =
155
- any ( Function f | f .hasQualifiedName ( "strings" , "ReplaceAll" ) ) .getACall ( ) and
156
+ cleanCall = any ( Function f | f .hasQualifiedName ( "strings" , "ReplaceAll" ) ) .getACall ( ) and
156
157
valueNode = cleanCall .getArgument ( 1 ) and
157
158
valueNode .asExpr ( ) .( StringLit ) .getValue ( ) = [ ".." , "." ] and
158
159
this = cleanCall .getResult ( )
0 commit comments