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

Configure GovukContentSecurityPolicy for govuk_app_config changes #2075

Merged
merged 2 commits into from
Jan 25, 2023

Conversation

kevindew
Copy link
Member

Trello: https://trello.com/c/lxxx5XLZ/178-govuk-has-a-half-implemented-content-security-policy-csp

This configures the content security policy in preparation for the
breaking changes coming from
alphagov/govuk_app_config#279. As this app uses
govuk_admin_template and that uses jQuery 1.x and inline script tags,
then this app needs unsafe_inline for script and the nonce generator
disabled.

As an aside, It was a surprise that this application had configured the
GovukContentSecurityPolicy as this had been initially done just in
Frontend apps and it looks like this made it through in some outsourced
Rails updates 1. I'm leaving this config in so there is an example of
an app outside of frontend using it to build on and as a case study in
configuring an app.


⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.

This resolves this app having both a csp and content_security_policy.rb
file.

We choose the latter one as it is a Rails default that will get
automatically added on Rails upgrades.
This configures the content security policy in preparation for the
breaking changes coming from
alphagov/govuk_app_config#279. As this app uses
govuk_admin_template and that uses jQuery 1.x and inline script tags,
then this app needs unsafe_inline for script and the nonce generator
disabled.

As an aside, It was a surprise that this application had configured the
GovukContentSecurityPolicy as this had been initially done just in
Frontend apps and it looks like this made it through in some outsourced
Rails updates [1]. I'm leaving this config in so there is an example of
an app outside of frontend using it to build on and as a case study in
configuring an app.

[1]: 45a5a51
# required for compatibility with govuk_admin_template which both uses script
# tags without nonces and uses jQuery 1.x which requires unsafe-inline in
# some browsers (Firefox is one)
script_policy_with_unsafe_inline = (policy.script_src + ["'unsafe-inline'"]).uniq
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming the double quotes here is intended and not a typo, but just checking?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, thanks. They're intentional - we need unsafe-inline in quotes.

Copy link
Contributor

@BeckaL BeckaL left a comment

Choose a reason for hiding this comment

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

Looks OK to me (somewhat limited knowledge here)

@kevindew
Copy link
Member Author

Thanks for the review @BeckaL - yup I've had to learn this stuff quite quickly, it'll be a whole safe new future!

@kevindew kevindew merged commit a752f7f into main Jan 25, 2023
@kevindew kevindew deleted the test-csp branch January 25, 2023 17:13
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.

2 participants