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

SHA256 for CSP #432

Open
chongfai13 opened this issue Feb 25, 2020 · 7 comments
Open

SHA256 for CSP #432

chongfai13 opened this issue Feb 25, 2020 · 7 comments

Comments

@chongfai13
Copy link

@chongfai13 chongfai13 commented Feb 25, 2020

Hi there

I would like to create random hashes from the inline script by using sha256 like the following results:

Content-Security-Policy: script-src 'sha256-B2yPHKaXnvFWtRChIbabYmUBFZdVfKKXHbWtWidDVF8='

Appreciate for your kind asist.

Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src

@oreoshake
Copy link
Member

@oreoshake oreoshake commented Feb 25, 2020

@chongfai13 you should be able to add those values directly into your config. There's also an automated tool for dynamically applying specific hashes but I'm not sure anyone uses it https://github.com/github/secure_headers/blob/master/docs/hashes.md

@oreoshake oreoshake closed this Feb 25, 2020
@chongfai13
Copy link
Author

@chongfai13 chongfai13 commented Mar 2, 2020

Hi Oreoshake

Thanks for your reply, we have followed the instructions but unfortunately it’s not working. Can you advise or perhaps show me the steps?
Thanks

@oreoshake
Copy link
Member

@oreoshake oreoshake commented Mar 2, 2020

@chongfai13 Can you provide more details about what is not working? Did the rake task execute? Are the hashes being generated (config/secure_headers_generated_hashes.yml)? Are the hashes being included in the header? Are the hashes wrong?

@chongfai13
Copy link
Author

@chongfai13 chongfai13 commented Mar 3, 2020

Hi Oreshake, yes, the file config/secure_headers_generated_hashes.yml is generated with the content:

(three dashes)
scripts: {}
styles: {}

and these hashes not included in the header. Please help

@oreoshake
Copy link
Member

@oreoshake oreoshake commented Mar 3, 2020

And you have raw <script> "javascript_goes_here" </script> tags in your views? It uses a regular expression to try and find script tags but I wouldn't call it well tested.

@oreoshake oreoshake reopened this Mar 3, 2020
@chongfai13
Copy link
Author

@chongfai13 chongfai13 commented Mar 9, 2020

Hi Oreoshake, sorry for late reply, you may see my source code here: https://github.com/chongfai13/secure_headers

I have successfully made the hashes, question: How do I set it at the headers?

I wish to create like this:
Content-Security-Policy: script-src 'sha256-B2yPHKaXnvFWtRChIbabYmUBFZdVfKKXHbWtWidDVF8='

Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src

@oreoshake
Copy link
Member

@oreoshake oreoshake commented Mar 13, 2020

Hi @chongfai13 it looks like that test repo is enough for to me to look into this, thanks for putting that together. Unfortunately, I'm very busy so it may be some time before I can get to it. I've set a reminder so I (hopefully) won't forget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.