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

Create secure request when site port is 443 or SECURE_SSL_REDIRECT is set to True #25

Closed
wants to merge 1 commit into from
Closed

Create secure request when site port is 443 or SECURE_SSL_REDIRECT is set to True #25

wants to merge 1 commit into from

Conversation

loicteixeira
Copy link
Collaborator

Fix #24 (Generated pages are blank when SECURE_SSL_REDIRECT is enabled).

@@ -88,8 +88,9 @@ def build_object(self, obj):
"""
site = obj.get_site()
logger.debug("Building %s" % obj)
secure_request = site.port == 443 or getattr(settings, 'SECURE_SSL_REDIRECT', 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.

I decided to also check for the site port. I'll add some tests later if you agree with the change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Eh.. It appears to be breaking some tests, but only for some versions of Python.. Anyway, I'll wait for your feedback before looking at it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the notice @loicteixeira . In which case are you trying to build pages via ssl? Almost every site runs in http modus, as ssl offloading is done on LB level or page building is done on local machine. In this really necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The app is hosted on Heroku and as per their requirement, the SSL redirection needs to be performed at the application level.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@robmoorman Any further thoughts on the approach then? Maybe you would prefer it to be a BAKERY_SECURE_REQUESTS setting which defaults to False instead of the automatic detection?

@coveralls
Copy link

coveralls commented Feb 3, 2018

Coverage Status

Coverage increased (+0.1%) to 73.832% when pulling 9cd67bc on loicteixeira:fix/24-blank-page-when-enforcing-ssl into 4c29799 on moorinteractive:master.

@loicteixeira
Copy link
Collaborator Author

I'll use a custom view on the app instead. Thanks.

stevejalim pushed a commit to mdn/developer-portal that referenced this pull request Sep 23, 2019
…bakes out empty HTML

This commit subclasses wagtail-bakery's `AllPublishedPagesView` in a way that detects
application-level SSL redirection in order to avoid an issue where rendered pages end up
being 0 bytes.

See wagtail-nest/wagtail-bakery#24 for confirmation of the
issue and the discussion on wagtail-nest/wagtail-bakery#25
that points to a custom view being the (current) workaround. Ideally we'll be
able to replace this when that issue is resolved.

The code in this commit is basically taken from that closed PR, which adds the
`secure_request` variable. Hat-tip to @loicteixeira - thanks!

No unit test added, but manually tested locally to confirm this does indeed fix the
static build while `SECURE_SSL_REDIRECT` is `True`
stevejalim pushed a commit to mdn/developer-portal that referenced this pull request Sep 25, 2019
* 22: Enable recommended-by-Django security settings as defaults

The base settings now follow all-but-one of the recommendations from manage.py `check --deploy`.
The only one that's not been done in this changeset is SECURE_HSTS_SECONDS, because of the risk of "serious, irreversible problems". That needs to be planned in to enable it properly.

Note that we're explicitly setting what HTTP header to look for to detect the SSL-forwarded header, which should stop the redirect loop in production.

Development settings turn off SSL redirect, because the local build isn't set to use HTTPS. (It could be tweaked to use HTTPS, too - but that's out of scope for this piece)

* 22: Address issue with wagtail-bakery where SECURE_SSL_REDIRECT=True bakes out empty HTML

This commit subclasses wagtail-bakery's `AllPublishedPagesView` in a way that detects
application-level SSL redirection in order to avoid an issue where rendered pages end up
being 0 bytes.

See wagtail-nest/wagtail-bakery#24 for confirmation of the
issue and the discussion on wagtail-nest/wagtail-bakery#25
that points to a custom view being the (current) workaround. Ideally we'll be
able to replace this when that issue is resolved.

The code in this commit is basically taken from that closed PR, which adds the
`secure_request` variable. Hat-tip to @loicteixeira - thanks!

No unit test added, but manually tested locally to confirm this does indeed fix the
static build while `SECURE_SSL_REDIRECT` is `True`
William-Blackie pushed a commit to William-Blackie/Wagtail-Backery-Squash-POC that referenced this pull request Aug 3, 2020
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.

3 participants