github / github/secure_headers

`content_security_policy_nonce` calls Rails method so CSP does not contain nonce

Đang mở
#511 2 bình luận 1 reaction 2 người được giao Được @fletchto99 nhận Xem trên GitHub
Ngôn ngữ chính
Ruby
Star
3.2k
Fork
253
Merge trung bình
19 giờ 11 phút
Pull request đã merge (30 ngày)
1

Mô tả

### 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_static_path(:bootstrap, format: :js, v: GoodJob::VERSION, locale: nil), nonce: content_security_policy_nonce %>
```

([link to code](https://github.com/bensheldon/good_job/blob/c71c3b338326bc14fb0ec58eaf70f6ee66c20c02/app/views/layouts/good_job/application.html.erb#L14))

I would expect Secure Headers to set the nonce in the CSP header so that these scripts are permitted.

### Actual outcome

No 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.

I 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.

Possible related issues:
- https://github.com/github/secure_headers/issues/392
- https://github.com/github/secure_headers/pull/389

### Config

```
SecureHeaders::Configuration.default do |config|
config.hsts = "max-age=#{1.year.to_i}; includeSubDomains; preload"
config.x_frame_options = 'DENY'
config.x_content_type_options = 'nosniff'
config.x_xss_protection = '1; mode=block'
config.x_download_options = 'noopen'
config.x_permitted_cross_domain_policies = 'none'
config.referrer_policy = %w[origin-when-cross-origin
strict-origin-when-cross-origin]
config.csp = {
default_src: %w['none'],
script_src: %w['self' http://www.google-analytics.com],
connect_src: %w['self'],
frame_ancestors: %w['none'],
font_src: %w['self' data: https://fonts.gstatic.com],
img_src: %w['self' data: https://validator.swagger.io],
style_src: %w['self' https://fonts.googleapis.com],
}
end
```

### Generated headers

```
default-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
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.