Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update settings so that SSL upgrade is not done, because it happens at the CDN/LB #148

Merged
merged 2 commits into from
Oct 17, 2023

Conversation

stevejalim
Copy link
Collaborator

@stevejalim stevejalim commented Oct 13, 2023

The CDN redirects non-https to https, so we don't need to do it in the app.

This approach means we avoid risk of a cache-poisoning attack for that http->https upgrade.

Resolves #143

@stevejalim
Copy link
Collaborator Author

@bkochendorfer Am i right that the CDN-level HTTP->HTTPS redirect we get in bedrock is also how things work for birdbox? If so, does this all seem 👍 to you?

) # so default: "True"
if config("USE_SECURE_PROXY_HEADER", default=str(SECURE_SSL_REDIRECT), parser=bool):
)
if config("USE_SECURE_PROXY_HEADER", default="True", parser=bool):
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't need this anymore either, right? Or it should at least default to False?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I assumed we did need it, cos the CDN/LB infra was terminating HTTPS and forwarding on.

My thought process was more or less: Because we know it'll all be over HTTPS maybe we don't need it, but if it's not used then the docs ready like HttpRequest.is_secure() may return False, which could break other things (eg CSRF for the Wagtail side).

You could be totally right, though! I'll think on it a bit more

Copy link
Member

Choose a reason for hiding this comment

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

On bedrock we short-circuit that was some trickery in the wsgi file. https://github.com/mozilla/bedrock/blob/d6d71498b4278fa3e6c5bdec2fe41b8861d2c2f9/wsgi/app.py#L16-L21

Copy link
Member

Choose a reason for hiding this comment

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

due to it already being HTTPS, as guaranteed by the CDN, someone sending a request with x-forwarded-proto: http could poison the cache because that would cause Django to return a redirect to https which would then loop because the redirect response would be cached.

Copy link
Member

Choose a reason for hiding this comment

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

unless GCP CDN is sending an accurate x-forwarded-proto header. it seems cloudfront is not.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should set it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm so https://cloud.google.com/load-balancing/docs/https#target-proxies says x-forwarded-proto is set by different load balancer options but it's hard to determine whether Cloud CDN nixes that. @bkochendorfer Are we using the classic LB or the Global external Application Load Balancer please?

Copy link
Member

Choose a reason for hiding this comment

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

GKE Ingress which is a Classic Application Load Balancer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've set this to default to False, but still be tweakable via env vars. Will merge it and see how it is on dev

Copy link
Collaborator Author

@stevejalim stevejalim Oct 17, 2023

Choose a reason for hiding this comment

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

Ugh so disabling the SSL_REDIRECT upgrade breaks the redirect URI generated by for django-oicd, breaking SSO. I've just reverted it on main to bring dev back in line. I think I'll try the wsgi trick Pmac mentions above in case that gives us the best of both worlds: no HTTP->S upgrade and a signal that we're on HTTPS (because effectively we will be)

Doing that work over in #154

…t the CDN/LB

The CDN redirects non-https to https, so we don't need to do it in the app.

This approach means we avoid risk of a cache-poisoning attack for that
http->https upgrade.
@stevejalim stevejalim force-pushed the adjust-https-redirect branch from 28914d6 to d1ecbe8 Compare October 17, 2023 14:13
@stevejalim stevejalim merged commit 5f2291b into main Oct 17, 2023
@stevejalim stevejalim deleted the adjust-https-redirect branch October 17, 2023 20:31
stevejalim added a commit that referenced this pull request Oct 17, 2023
@stevejalim stevejalim restored the adjust-https-redirect branch October 17, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable HTTP->S redirect at app level
3 participants