Skip to content

Commit 6d0783a

Browse files
committed
Python: Make sure that expected values with tag mimetype is wrapped in quotes if the value contains a space.
1 parent fc80ef2 commit 6d0783a

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
| response_test.py:21:12:21:56 | ControlFlowNode for HttpResponseRedirect() | Unexpected result: mimetype=text/html; charset=utf-8 |
2-
| response_test.py:21:59:21:132 | Comment # $HttpResponse mimetype=text/html; charset=utf-8 responseBody=Attribute() | Missing result:mimetype=text/html; |
3-
| response_test.py:25:12:25:56 | ControlFlowNode for HttpResponseNotFound() | Unexpected result: mimetype=text/html; charset=utf-8 |
4-
| response_test.py:25:59:25:132 | Comment # $HttpResponse mimetype=text/html; charset=utf-8 responseBody=Attribute() | Missing result:mimetype=text/html; |
5-
| response_test.py:32:16:32:29 | ControlFlowNode for HttpResponse() | Unexpected result: mimetype=text/html; charset=utf-8 |
6-
| response_test.py:32:32:32:80 | Comment # $HttpResponse mimetype=text/html; charset=utf-8 | Missing result:mimetype=text/html; |
7-
| response_test.py:33:5:33:43 | ControlFlowNode for Attribute() | Unexpected result: mimetype=text/html; charset=utf-8 |
8-
| response_test.py:33:46:33:119 | Comment # $HttpResponse mimetype=text/html; charset=utf-8 responseBody=Attribute() | Missing result:mimetype=text/html; |

python/ql/test/experimental/library-tests/frameworks/django-v1/response_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ def safe__manual_content_type(request):
1818
# XSS FP reported in https://github.com/github/codeql/issues/3466
1919
# Note: This should be an open-redirect sink, but not an XSS sink.
2020
def or__redirect(request):
21-
return HttpResponseRedirect(request.GET.get("next")) # $HttpResponse mimetype=text/html; charset=utf-8 responseBody=Attribute()
21+
return HttpResponseRedirect(request.GET.get("next")) # $HttpResponse mimetype="text/html; charset=utf-8" responseBody=Attribute()
2222

2323
# Ensure that simple subclasses are still vuln to XSS
2424
def xss__not_found(request):
25-
return HttpResponseNotFound(request.GET.get("name")) # $HttpResponse mimetype=text/html; charset=utf-8 responseBody=Attribute()
25+
return HttpResponseNotFound(request.GET.get("name")) # $HttpResponse mimetype="text/html; charset=utf-8" responseBody=Attribute()
2626

2727
# Ensure we still have an XSS sink when manually setting the content_type to HTML
2828
def xss__manual_response_type(request):
2929
return HttpResponse(request.GET.get("name"), content_type="text/html; charset=utf-8") # $HttpResponse mimetype=text/html responseBody=Attribute()
3030

3131
def xss__write(request):
32-
response = HttpResponse() # $HttpResponse mimetype=text/html; charset=utf-8
33-
response.write(request.GET.get("name")) # $HttpResponse mimetype=text/html; charset=utf-8 responseBody=Attribute()
32+
response = HttpResponse() # $HttpResponse mimetype="text/html; charset=utf-8"
33+
response.write(request.GET.get("name")) # $HttpResponse mimetype="text/html; charset=utf-8" responseBody=Attribute()
3434

3535
# This is safe but probably a bug if the argument to `write` is not a result of `json.dumps` or similar.
3636
def safe__write_json(request):

python/ql/test/experimental/meta/ConceptsTest.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ class HttpServerHttpResponseTest extends InlineExpectationsTest {
178178
exists(HTTP::Server::HttpResponse response |
179179
___location = response.getLocation() and
180180
element = response.toString() and
181-
value = response.getMimetype() and
181+
// Ensure that an expectation value such as "mimetype=text/html; charset=utf-8" is parsed as a
182+
// single expectation with tag mimetype, and not as two expecations with tags mimetype and
183+
// charset.
184+
(
185+
if exists(response.getMimetype().indexOf(" "))
186+
then value = "\"" + response.getMimetype() + "\""
187+
else value = response.getMimetype()
188+
) and
182189
tag = "mimetype"
183190
)
184191
)

0 commit comments

Comments
 (0)