Skip to content

Commit 6a77a20

Browse files
go with safe chars approach from werkzeug
1 parent a54f6ab commit 6a77a20

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mauth_client/middlewares/wsgi.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def _extract_headers(self, environ):
8484

8585
return headers
8686

87+
SAFE_CHARS = "!$&'()*+,/:;=@%"
88+
8789
def _extract_url(self, environ):
8890
"""
8991
Adapted from https://peps.python.org/pep-0333/#url-reconstruction
@@ -101,11 +103,15 @@ def _extract_url(self, environ):
101103
if (scheme == "https" and port != 443) or (scheme != "https" and port != 80):
102104
url_parts.append(f":{port}")
103105

104-
url_parts.append(quote(environ.get("SCRIPT_NAME", "")))
105-
url_parts.append(quote(environ.get("PATH_INFO"), ""))
106+
url_parts.append(
107+
quote(environ.get("SCRIPT_NAME", ""), safe=self.SAFE_CHARS)
108+
)
109+
url_parts.append(
110+
quote(environ.get("PATH_INFO", ""), safe=self.SAFE_CHARS)
111+
)
106112

107113
qs = environ.get("QUERY_STRING")
108114
if qs:
109-
url_parts.append(f"?{qs}")
115+
url_parts.append(f"?{quote(qs, safe=self.SAFE_CHARS)}")
110116

111117
return "".join(url_parts)

0 commit comments

Comments
 (0)