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 {
7171 Http:: Server:: ResponseHeaderBulkWrite .super .valueAllowsNewline ( )
7272 }
7373 }
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+ }
7484}
Original file line number Diff line number Diff line change @@ -58,4 +58,13 @@ def flask_make_response_header_arg3():
5858def flask_make_response_header_arg2 ():
5959 rfs_header = request .args ["rfs_header" ]
6060 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