Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
oioki committed Jul 5, 2023
1 parent 8d836ea commit ee44c6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/sentry/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def allow_cors_options_wrapper(self, request: Request, *args, **kwargs):
# to be sent.
basehost = options.get("system.base-hostname")
if basehost and origin:
if origin.endswith(basehost):
if origin.endswith(("://" + basehost, "." + basehost)):
response["Access-Control-Allow-Credentials"] = "true"

return response
Expand Down
17 changes: 9 additions & 8 deletions tests/sentry/api/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,16 @@ def test_allow_credentials_incorrect(self):
org = self.create_organization()
apikey = ApiKey.objects.create(organization_id=org.id, allowed_origins="*")

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

response = _dummy_endpoint(request)
response.render()
assert "Access-Control-Allow-Credentials" not in response
response = _dummy_endpoint(request)
response.render()
assert "Access-Control-Allow-Credentials" not in response

def test_invalid_cors_without_auth(self):
request = self.make_request(method="GET")
Expand Down

0 comments on commit ee44c6b

Please sign in to comment.