Skip to content

Commit 5a67a56

Browse files
Merge commit from fork
Remove open redirect in Location header normalization
2 parents 0a69ff1 + 192d03f commit 5a67a56

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

CHANGES.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Unreleased
22
----------
33

4+
Security Fix
5+
~~~~~~~~~~~~
6+
7+
- The use of WebOb's Response object to redirect a request to a new location
8+
can lead to an open redirect if the Location header is not a full URI.
9+
10+
See https://github.com/Pylons/webob/security/advisories/GHSA-mg3v-6m49-jhp3
11+
and CVE-2024-42353
12+
13+
Thanks to Sara Gao for the report
14+
15+
(This fix was released in WebOb 1.8.8)
16+
417
Feature
518
~~~~~~~
619

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
"pytest-xdist",
1919
]
2020

21-
docs_extras = ["Sphinx >= 1.7.5", "pylons-sphinx-themes"]
21+
docs_extras = [
22+
"Sphinx >= 1.7.5",
23+
"pylons-sphinx-themes",
24+
"setuptools",
25+
]
2226

2327
setup(
2428
name="WebOb",

src/webob/response.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,11 @@ def _make_location_absolute(environ, value):
13591359
if SCHEME_RE.search(value):
13601360
return value
13611361

1362+
# This is to fix an open redirect issue due to the way that
1363+
# urlparse.urljoin works. See CVE-2024-42353 and
1364+
# https://github.com/Pylons/webob/security/advisories/GHSA-mg3v-6m49-jhp3
1365+
if value.startswith("//"):
1366+
value = f"/%2f{value[2:]}"
13621367
new_location = urlparse.urljoin(_request_uri(environ), value)
13631368

13641369
return new_location

tests/test_response.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,17 @@ def test_location():
10851085
assert req.get_response(res).location == "http://localhost/test2.html"
10861086

10871087

1088+
def test_location_no_open_redirect():
1089+
# This is a test for a fix for CVE-2024-42353 and
1090+
# https://github.com/Pylons/webob/security/advisories/GHSA-mg3v-6m49-jhp3
1091+
res = Response()
1092+
res.status = "301"
1093+
res.location = "//www.example.com/test"
1094+
assert res.location == "//www.example.com/test"
1095+
req = Request.blank("/")
1096+
assert req.get_response(res).location == "http://localhost/%2fwww.example.com/test"
1097+
1098+
10881099
@pytest.mark.xfail(
10891100
sys.version_info < (3, 0),
10901101
reason="Python 2.x unicode != str, WSGI requires str. Test "

0 commit comments

Comments
 (0)