File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
lib/semmle/python/security/dataflow Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -71,4 +71,14 @@ module HttpHeaderInjection {
71
71
Http:: Server:: ResponseHeaderBulkWrite .super .valueAllowsNewline ( )
72
72
}
73
73
}
74
+
75
+ /**
76
+ * A call to replace line breaks, considered as a sanitizer.
77
+ */
78
+ class ReplaceLineBreaksSanitizer extends Sanitizer , DataFlow:: CallCfgNode {
79
+ ReplaceLineBreaksSanitizer ( ) {
80
+ this .getFunction ( ) .( DataFlow:: AttrRead ) .getAttributeName ( ) = "replace" and
81
+ this .getArg ( 0 ) .asExpr ( ) .( StrConst ) .getText ( ) = "\n"
82
+ }
83
+ }
74
84
}
Original file line number Diff line number Diff line change @@ -58,4 +58,13 @@ def flask_make_response_header_arg3():
58
58
def flask_make_response_header_arg2 ():
59
59
rfs_header = request .args ["rfs_header" ]
60
60
resp = make_response ("hello" , {request .args ["rfs_header" ]: "HeaderValue" }) # BAD
61
- return resp
61
+ return resp
62
+
63
+ @app .route ("/flask_escaped" )
64
+ def flask_escaped ():
65
+ rfs_header = request .args ["rfs_header" ]
66
+ resp = make_response ("hello" , {rfs_header .replace ("\n " , "" ): "HeaderValue" }) # GOOD - Newlines are removed from the input.
67
+ return resp
68
+
69
+ # if __name__ == "__main__":
70
+ # app.run(debug=True)
You can’t perform that action at this time.
0 commit comments