66import go
77import semmle.go.dataflow.barrierguardutil.RegexpCheck
88import DataFlow
9+
910/**
1011 * Provides extension points for customizing the taint tracking configuration for reasoning about
1112 * path-traversal vulnerabilities.
@@ -79,15 +80,15 @@ module TaintedPath {
7980 class FilepathCleanSanitizer extends Sanitizer {
8081 FilepathCleanSanitizer ( ) {
8182 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
8484 concatNode = cleanCall .getArgument ( 0 ) and
8585 concatNode .getOperand ( 0 ) .asExpr ( ) .( StringLit ) .getValue ( ) = "/" and
8686 this = cleanCall .getResult ( )
8787 )
8888 }
8989 }
90- /**
90+
91+ /**
9192 * A call to `filepath.Base(e)`, considered to sanitize `e` against path traversal.
9293 */
9394 class FilepathBaseSanitizer extends Sanitizer {
@@ -107,8 +108,8 @@ module TaintedPath {
107108 frn .getField ( ) .hasQualifiedName ( "mime/multipart" , "FileHeader" , "Filename" ) and
108109 this = frn
109110 )
110- }
111111 }
112+ }
112113
113114 /**
114115 * A check of the form `!strings.Contains(nd, "..")`, considered as a sanitizer guard for
@@ -127,15 +128,15 @@ module TaintedPath {
127128 branch = false
128129 }
129130 }
130- /**
131+
132+ /**
131133 * A replacement of the form `!strings.ReplaceAll(nd, "..")` or `!strings.ReplaceAll(nd, ".")`, considered as a sanitizer for
132134 * path traversal.
133135 */
134136 class DotDotReplace extends Sanitizer {
135137 DotDotReplace ( ) {
136138 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
139140 valueNode = cleanCall .getArgument ( 1 ) and
140141 valueNode .asExpr ( ) .( StringLit ) .getValue ( ) = [ ".." , "." ] and
141142 this = cleanCall .getResult ( )
0 commit comments