From 1c2e4baecbea55b4333dd18294a119111365448f Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Thu, 11 Mar 2021 01:27:57 +0000 Subject: [PATCH] Fix tests for all urllib versions with only '&' as separator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turns out #14698 did not fix the issue as Master failed again. After digging a bit more I found that the CVE was fixed in all Python versions: 3.6.13, 3.7.10 & 3.8.8 The solution in this PR/commit checks the `parse_qsl` behavior with following tests: ``` ❯ docker run -it python:3.8-slim bash root@41120dfd035e:/# python Python 3.8.8 (default, Feb 19 2021, 18:07:06) >>> from urllib.parse import parse_qsl >>> parse_qsl(";a=b") [(';a', 'b')] >>> ``` ❯ docker run -it python:3.8.7-slim bash root@68e527725610:/# python Python 3.8.7 (default, Feb 9 2021, 08:21:15) >>> from urllib.parse import parse_qsl >>> parse_qsl(";a=b") [('a', 'b')] >>> ``` --- tests/www/test_views.py | 88 ++++++++++------------------------------- 1 file changed, 21 insertions(+), 67 deletions(-) diff --git a/tests/www/test_views.py b/tests/www/test_views.py index 517d4bc56f997..5ef5a2193f111 100644 --- a/tests/www/test_views.py +++ b/tests/www/test_views.py @@ -32,7 +32,7 @@ from typing import Any, Dict, Generator, List, NamedTuple from unittest import mock from unittest.mock import PropertyMock -from urllib.parse import quote_plus +from urllib.parse import parse_qsl, quote_plus import jinja2 import pytest @@ -2772,33 +2772,6 @@ def test_trigger_dag_form(self): resp = self.client.get(f'trigger?dag_id={test_dag_id}') self.check_content_in_response(f'Trigger DAG: {test_dag_id}', resp) - @parameterized.expand( - [ - ("javascript:alert(1)", "/home"), - ("http://google.com", "/home"), - ( - "%2Ftree%3Fdag_id%3Dexample_bash_operator';alert(33)//", - "/tree?dag_id=example_bash_operator%27&alert%2833%29%2F%2F=", - ), - ("%2Ftree%3Fdag_id%3Dexample_bash_operator", "/tree?dag_id=example_bash_operator"), - ("%2Fgraph%3Fdag_id%3Dexample_bash_operator", "/graph?dag_id=example_bash_operator"), - ] - ) - @pytest.mark.skipif( - sys.version_info < (3, 8, 8), - reason='Vulnerability was fixed in Python 3.8.8 which changed the query string separator: bpo-42967', - ) - def test_trigger_dag_form_origin_url_py_lte_387(self, test_origin, expected_origin): - test_dag_id = "example_bash_operator" - - resp = self.client.get(f'trigger?dag_id={test_dag_id}&origin={test_origin}') - self.check_content_in_response( - '