Skip to content

Commit ee44c6b

Browse files
authored
1 parent 8d836ea commit ee44c6b

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/sentry/api/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def allow_cors_options_wrapper(self, request: Request, *args, **kwargs):
121121
# to be sent.
122122
basehost = options.get("system.base-hostname")
123123
if basehost and origin:
124-
if origin.endswith(basehost):
124+
if origin.endswith(("://" + basehost, "." + basehost)):
125125
response["Access-Control-Allow-Credentials"] = "true"
126126

127127
return response

tests/sentry/api/test_base.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,16 @@ def test_allow_credentials_incorrect(self):
162162
org = self.create_organization()
163163
apikey = ApiKey.objects.create(organization_id=org.id, allowed_origins="*")
164164

165-
request = self.make_request(method="GET")
166-
request.META["HTTP_ORIGIN"] = "http://acme.example.com"
167-
request.META["HTTP_AUTHORIZATION"] = b"Basic " + base64.b64encode(
168-
apikey.key.encode("utf-8")
169-
)
165+
for http_origin in ["http://acme.example.com", "http://fakeacme.com"]:
166+
request = self.make_request(method="GET")
167+
request.META["HTTP_ORIGIN"] = http_origin
168+
request.META["HTTP_AUTHORIZATION"] = b"Basic " + base64.b64encode(
169+
apikey.key.encode("utf-8")
170+
)
170171

171-
response = _dummy_endpoint(request)
172-
response.render()
173-
assert "Access-Control-Allow-Credentials" not in response
172+
response = _dummy_endpoint(request)
173+
response.render()
174+
assert "Access-Control-Allow-Credentials" not in response
174175

175176
def test_invalid_cors_without_auth(self):
176177
request = self.make_request(method="GET")

0 commit comments

Comments
 (0)