@@ -934,6 +934,27 @@ def test_set_status_with_empty_reason() -> None:
934934 assert resp .reason == ""
935935
936936
937+ def test_set_status_reason_with_cr () -> None :
938+ resp = web .StreamResponse ()
939+
940+ with pytest .raises (ValueError , match = "Reason cannot contain" ):
941+ resp .set_status (200 , "OK\r Set-Cookie: evil=1" )
942+
943+
944+ def test_set_status_reason_with_lf () -> None :
945+ resp = web .StreamResponse ()
946+
947+ with pytest .raises (ValueError , match = "Reason cannot contain" ):
948+ resp .set_status (200 , "OK\n Set-Cookie: evil=1" )
949+
950+
951+ def test_set_status_reason_with_crlf () -> None :
952+ resp = web .StreamResponse ()
953+
954+ with pytest .raises (ValueError , match = "Reason cannot contain" ):
955+ resp .set_status (200 , "OK\r \n Set-Cookie: evil=1" )
956+
957+
937958async def test_start_force_close () -> None :
938959 req = make_request ("GET" , "/" )
939960 resp = web .StreamResponse ()
@@ -1236,7 +1257,7 @@ async def test_render_with_body(buf: bytearray, writer: AbstractStreamWriter) ->
12361257
12371258
12381259async def test_multiline_reason (buf : bytearray , writer : AbstractStreamWriter ) -> None :
1239- with pytest .raises (ValueError , match = r"Reason cannot contain \\n" ):
1260+ with pytest .raises (ValueError , match = r"Reason cannot contain \\r or \\ n" ):
12401261 web .Response (reason = "Bad\r \n Injected-header: foo" )
12411262
12421263
0 commit comments