Skip to content

Commit ebec33d

Browse files
Merge pull request #507 from rohanpm/uri-decoding
Implement missing URI decoding step [RHELDST-20564]
2 parents cdef02b + 3100394 commit ebec33d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

exodus_lambda/functions/origin_request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import time
55
import urllib
6+
import urllib.parse
67
from datetime import datetime, timedelta, timezone
78

89
import boto3
@@ -354,6 +355,8 @@ def handler(self, event, context):
354355
extra={"request": request},
355356
)
356357

358+
request["uri"] = urllib.parse.unquote(request["uri"])
359+
357360
if request["uri"].startswith("/_/cookie/"):
358361
return self.handle_cookie_request(event)
359362

tests/functions/test_origin_request.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
import urllib
4+
import urllib.parse
45

56
import mock
67
import pytest
@@ -63,6 +64,26 @@
6364
"/content/dist/rhel/server/7/7.9/file.ext",
6465
"text/plain",
6566
),
67+
(
68+
# encoded URI should be decoded
69+
"/content/dist/rhel/rhui/server/7/7Server/some%5Efile",
70+
"/content/dist/rhel/server/7/7.9/some^file",
71+
"text/plain",
72+
),
73+
(
74+
# but it is also OK to not encode that character
75+
"/content/dist/rhel/rhui/server/7/7Server/some^file",
76+
"/content/dist/rhel/server/7/7.9/some^file",
77+
"text/plain",
78+
),
79+
(
80+
# this tricky case is trying to ensure that, even for "special"
81+
# paths like /listing, if the client encodes parts of the URI it
82+
# still all works normally.
83+
"/content/dist/rhel/rhui/server/7/li%73ting",
84+
"/content/dist/rhel/rhui/server/7/listing",
85+
"text/plain",
86+
),
6687
],
6788
ids=[
6889
"/origin/rpm/",
@@ -74,6 +95,9 @@
7495
"no alias keywords",
7596
"releasever alias",
7697
"layered rhui, releasever alias",
98+
"encoded URI",
99+
"reserved char no encoding",
100+
"encoded listing",
77101
],
78102
)
79103
@mock.patch("boto3.client")
@@ -110,7 +134,9 @@ def test_origin_request(
110134

111135
assert "Incoming request value for origin_request" in caplog.text
112136

113-
if req_uri.endswith("/listing"):
137+
req_uri_decoded = urllib.parse.unquote(req_uri)
138+
139+
if req_uri_decoded.endswith("/listing"):
114140
assert "Handling listing request" in caplog.text
115141
assert "Generated listing request response" in caplog.text
116142
assert request["body"]
@@ -123,7 +149,7 @@ def test_origin_request(
123149
),
124150
"headers": {
125151
"exodus-original-uri": [
126-
{"key": "exodus-original-uri", "value": req_uri}
152+
{"key": "exodus-original-uri", "value": req_uri_decoded}
127153
]
128154
},
129155
}

0 commit comments

Comments
 (0)