Title: `content_security_policy_nonce` calls Rails method so CSP does not contain nonce · Issue #511 · github/secure_headers · GitHub
Open Graph Title: `content_security_policy_nonce` calls Rails method so CSP does not contain nonce · Issue #511 · github/secure_headers
X Title: `content_security_policy_nonce` calls Rails method so CSP does not contain nonce · Issue #511 · github/secure_headers
Description: Expected outcome I am using GoodJob to process jobs on Rails 6. The GoodJob dashboard includes a number of scripts and styles. These all have nonces set using the content_security_policy_nonce method. <%= tag.script "", src: frontend_sta...
Open Graph Description: Expected outcome I am using GoodJob to process jobs on Rails 6. The GoodJob dashboard includes a number of scripts and styles. These all have nonces set using the content_security_policy_nonce meth...
X Description: Expected outcome I am using GoodJob to process jobs on Rails 6. The GoodJob dashboard includes a number of scripts and styles. These all have nonces set using the content_security_policy_nonce meth...
Opengraph URL: https://github.com/github/secure_headers/issues/511
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`content_security_policy_nonce` calls Rails method so CSP does not contain nonce","articleBody":"### Expected outcome\r\nI am using GoodJob to process jobs on Rails 6. The GoodJob dashboard includes a number of scripts and styles. These all have nonces set using the `content_security_policy_nonce` method.\r\n```\r\n \u003c%= tag.script \"\", src: frontend_static_path(:bootstrap, format: :js, v: GoodJob::VERSION, locale: nil), nonce: content_security_policy_nonce %\u003e\r\n```\r\n\r\n([link to code](https://github.com/bensheldon/good_job/blob/c71c3b338326bc14fb0ec58eaf70f6ee66c20c02/app/views/layouts/good_job/application.html.erb#L14))\r\n\r\nI would expect Secure Headers to set the nonce in the CSP header so that these scripts are permitted.\r\n\r\n### Actual outcome\r\n\r\nNo nonce is set in the CSP header. I think that Rails' own `content_security_policy_nonce` method is being called rather than the Secure Headers method of the same name. This means that the CSP set by Secure Headers doesn't include the nonce, and the scripts and styles are therefore not permitted.\r\n\r\nI know that recommend practice when using Secure Headers is to use the `nonced_javascript_tag` method, but since this is in a gem I can't do that.\r\n\r\nPossible related issues:\r\n- https://github.com/github/secure_headers/issues/392\r\n- https://github.com/github/secure_headers/pull/389\r\n\r\n### Config\r\n\r\n```\r\nSecureHeaders::Configuration.default do |config|\r\n config.hsts = \"max-age=#{1.year.to_i}; includeSubDomains; preload\"\r\n config.x_frame_options = 'DENY'\r\n config.x_content_type_options = 'nosniff'\r\n config.x_xss_protection = '1; mode=block'\r\n config.x_download_options = 'noopen'\r\n config.x_permitted_cross_domain_policies = 'none'\r\n config.referrer_policy = %w[origin-when-cross-origin\r\n strict-origin-when-cross-origin]\r\n config.csp = {\r\n default_src: %w['none'],\r\n script_src: %w['self' http://www.google-analytics.com],\r\n connect_src: %w['self'],\r\n frame_ancestors: %w['none'],\r\n font_src: %w['self' data: https://fonts.gstatic.com],\r\n img_src: %w['self' data: https://validator.swagger.io],\r\n style_src: %w['self' https://fonts.googleapis.com],\r\n }\r\nend\r\n```\r\n\r\n### Generated headers\r\n\r\n```\r\ndefault-src 'none'; connect-src 'self'; font-src 'self' data: fonts.gstatic.com; frame-ancestors 'none'; img-src 'self' data: validator.swagger.io; script-src 'self' www.google-analytics.com; style-src 'self' fonts.googleapis.com\r\n```\r\n","author":{"url":"https://github.com/jdudley1123","@type":"Person","name":"jdudley1123"},"datePublished":"2023-09-20T12:50:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/511/secure_headers/issues/511"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8c35d767-054a-f2b4-836b-22238b458e25 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD66:2E67B:183EDE5:20E3045:6964B05A |
| html-safe-nonce | d4e993f027ae1238b0bc175091cf4dc4e9aebf128534fc40f0a04b347a9979f3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDY2OjJFNjdCOjE4M0VERTU6MjBFMzA0NTo2OTY0QjA1QSIsInZpc2l0b3JfaWQiOiI2NDc0NDk3ODA5ODg3NTcyMDU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 80251313e6aaf6525e1e057a4620fe21e8759235ee1003590f82c6142bcbd463 |
| hovercard-subject-tag | issue:1904928906 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/secure_headers/511/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a3f373a6e310c9c3cf9ee70d331a1fc34ffe7063d1eaf177fb9a0d381cd98f5f/github/secure_headers/issues/511 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a3f373a6e310c9c3cf9ee70d331a1fc34ffe7063d1eaf177fb9a0d381cd98f5f/github/secure_headers/issues/511 |
| og:image:alt | Expected outcome I am using GoodJob to process jobs on Rails 6. The GoodJob dashboard includes a number of scripts and styles. These all have nonces set using the content_security_policy_nonce meth... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jdudley1123 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 15579c46431b7fd25941c3b09010f74fd1890c7a35226839bbbf40ce70fb3057 |
| turbo-cache-control | no-preview |
| go-import | github.com/github/secure_headers git https://github.com/github/secure_headers.git |
| octolytics-dimension-user_id | 9919 |
| octolytics-dimension-user_login | github |
| octolytics-dimension-repository_id | 7122663 |
| octolytics-dimension-repository_nwo | github/secure_headers |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7122663 |
| octolytics-dimension-repository_network_root_nwo | github/secure_headers |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 499abb347cb197601d399c346cfeb4b3fa135d5c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width