File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
lib/semmle/python/frameworks
test/library-tests/frameworks/fastapi Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -383,5 +383,33 @@ module FastApi {
383
383
384
384
override predicate valueAllowsNewline ( ) { none ( ) }
385
385
}
386
+
387
+ class HeaderSubscriptWrite extends Http:: Server:: ResponseHeaderWrite:: Range {
388
+ DataFlow:: Node index ;
389
+ DataFlow:: Node value ;
390
+
391
+ HeaderSubscriptWrite ( ) {
392
+ exists ( SubscriptNode subscript , DataFlow:: AttrRead headerLookup |
393
+ // To give `this` a value, we need to choose between either LHS or RHS,
394
+ // and just go with the LHS
395
+ this .asCfgNode ( ) = subscript
396
+ |
397
+ headerLookup .accesses ( instance ( ) , "headers" ) and
398
+ exists ( DataFlow:: Node subscriptObj | subscriptObj .asCfgNode ( ) = subscript .getObject ( ) |
399
+ headerLookup .flowsTo ( subscriptObj )
400
+ ) and
401
+ value .asCfgNode ( ) = subscript .( DefinitionNode ) .getValue ( ) and
402
+ index .asCfgNode ( ) = subscript .getIndex ( )
403
+ )
404
+ }
405
+
406
+ override DataFlow:: Node getNameArg ( ) { result = index }
407
+
408
+ override DataFlow:: Node getValueArg ( ) { result = value }
409
+
410
+ override predicate nameAllowsNewline ( ) { none ( ) }
411
+
412
+ override predicate valueAllowsNewline ( ) { none ( ) }
413
+ }
386
414
}
387
415
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ async def response_parameter(response: Response): # $ requestHandler
13
13
response .set_cookie (key = "key" , value = "value" ) # $ CookieWrite CookieName="key" CookieValue="value"
14
14
response .headers .append ("Set-Cookie" , "key2=value2" ) # $ headerWriteName="Set-Cookie" headerWriteValue="key2=value2" CookieWrite CookieRawHeader="key2=value2"
15
15
response .headers .append (key = "Set-Cookie" , value = "key2=value2" ) # $ headerWriteName="Set-Cookie" headerWriteValue="key2=value2" CookieWrite CookieRawHeader="key2=value2"
16
- response .headers ["X-MyHeader" ] = "header-value" # $ MISSING: headerWriteName="X-MyHeader" headerWriteValue="header-value"
16
+ response .headers ["X-MyHeader" ] = "header-value" # $ headerWriteName="X-MyHeader" headerWriteValue="header-value"
17
17
response .status_code = 418
18
18
return {"message" : "response as parameter" } # $ HttpResponse mimetype=application/json responseBody=Dict
19
19
@@ -45,7 +45,7 @@ async def response_parameter_custom_type(response: MyXmlResponse): # $ requestHa
45
45
print (type (response ))
46
46
assert type (response ) == fastapi .responses .Response
47
47
response .set_cookie ("key" , "value" ) # $ CookieWrite CookieName="key" CookieValue="value"
48
- response .headers ["Custom-Response-Type" ] = "yes, but only after function has run" # $ MISSING: headerWriteName="Custom-Response-Typer " headerWriteValue="yes, but only after function has run"
48
+ response .headers ["Custom-Response-Type" ] = "yes, but only after function has run" # $ headerWriteName="Custom-Response-Type " headerWriteValue="yes, but only after function has run"
49
49
xml_data = "<foo>FOO</foo>"
50
50
return xml_data # $ HttpResponse responseBody=xml_data mimetype=application/xml
51
51
You can’t perform that action at this time.
0 commit comments