Skip to content

fix(hybrid-cloud): Do not bork at subdomain middleware if the host name is not RFC 1034/1035 compliant#37023

Merged
dashed merged 1 commit intomasterfrom
customer-domains/0-fix-subdomain-invalid-host
Aug 3, 2022
Merged

fix(hybrid-cloud): Do not bork at subdomain middleware if the host name is not RFC 1034/1035 compliant#37023
dashed merged 1 commit intomasterfrom
customer-domains/0-fix-subdomain-invalid-host

Conversation

@dashed
Copy link
Member

@dashed dashed commented Jul 25, 2022

HttpRequest.get_host() will raise django.core.exceptions.DisallowedHost if the HTTP_HOST header does not comply with RFC 1034/1035. In this case, we just bail out of the subdomain middleware early and continue processing the request.

Fixes SENTRY-VJD and others.

@dashed dashed requested a review from a team July 25, 2022 20:44
@dashed dashed self-assigned this Jul 25, 2022
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 25, 2022
@dashed dashed requested a review from a team July 26, 2022 17:47

host = request.get_host().lower()
try:
host = request.get_host().lower()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you still lowercase it if get_host fails?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoshFerge If an exception is raised in get_host(), I expect the chained lower() method to not be called at all.

I'm unsure if I understood what you meant by here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah needed to expand logic below to see how host was being used, that makes sense 👍🏼

@dashed dashed merged commit 1a1d803 into master Aug 3, 2022
@dashed dashed deleted the customer-domains/0-fix-subdomain-invalid-host branch August 3, 2022 04:12
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants