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

Add Rails CSP example to README #335

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,20 @@ CSP support for automatic insertion exposes two namespaces that can be defined b
- String CoreExtensions::IntercomRails::AutoInclude.csp_nonce_hook(controller)
- nil CoreExtensions::IntercomRails::AutoInclude.csp_sha256_hook(controller, SHA-256 whitelist entry)

For instance, a CSP nonce can be inserted using the [Twitter Secure Headers](https://github.com/twitter/secureheaders) gem with the following code:
For instance, a CSP nonce can be inserted using Rails' (5.2+) built-in [Content Security Policy](https://guides.rubyonrails.org/security.html#content-security-policy) configuration:
```ruby
module CoreExtensions
module IntercomRails
module AutoInclude
def self.csp_nonce_hook(controller)
controller.request.content_security_policy_nonce
end
end
end
end
```

Alternatively, use the [Twitter Secure Headers](https://github.com/twitter/secureheaders) gem with the following code:
```ruby
module CoreExtensions
module IntercomRails
Expand Down