-
Notifications
You must be signed in to change notification settings - Fork 77
Automatically add a nonce to script tag if a csp-nonce meta tag is available to get it from #101
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
Open
TylerRick
wants to merge
12
commits into
brentd:master
Choose a base branch
from
TylerRick:add_nonce
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
31daaee
Test on Rails 6
TylerRick 17c7148
Don't test so many old versions
TylerRick 9dc4c9c
Add www.example.com to config.hosts
TylerRick c0558bc
Update script_matcher to allow for .source and .debug suffixes that s…
TylerRick ec9ee88
Add end-to-end test that actually tests in a real browser that pressi…
TylerRick 8d3f195
Add capybara-screenshot so we can check out the .html document when a…
TylerRick 6fed81f
Load gems from Gemfile.local too, if present, so that developers can …
TylerRick 94e8147
Locked rspec-rails to 3.x in the .gemspec
TylerRick 1f1555c
Fix test error with Rails 6:
TylerRick b9efad2
Fix test failures on Rails < 6 due to sprockets >= 4
TylerRick 44a878e
In CI, we can't open the .html files saved by capybara-screenshot, so…
TylerRick 63c0210
Automatically add a nonce to script tag (#100)
TylerRick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ spec/dummy/db/*.sqlite3 | |
| spec/dummy/log/*.log | ||
| spec/dummy/tmp/ | ||
| spec/dummy/.sass-cache | ||
| Gemfile.local | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,15 @@ | ||
| source 'https://rubygems.org' | ||
| gemspec | ||
|
|
||
| gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION'] | ||
| if ENV['RAILS_VERSION'] | ||
| gem 'rails', ENV['RAILS_VERSION'] | ||
| if ENV['RAILS_VERSION'][/\d.*/] >= '6.0.0' | ||
| # use latest (4.x) | ||
| else | ||
| gem 'sprockets', '~> 3.0' | ||
| end | ||
| end | ||
|
|
||
| if (local_file = Pathname('Gemfile.local')).exist? | ||
| eval local_file.read, binding, __FILE__, __LINE__ | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| //= link_directory ../stylesheets .css | ||
| //= link_directory ../javascripts .js | ||
| //= link jquery.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| if Gem.loaded_specs['rails'].version >= Gem::Version.new('5.2.0') | ||
| Rails.application.config.content_security_policy do |policy| | ||
| # Empty. Only need one endpoint (/strict_csp) to use a strict CSP in our tests. | ||
| end | ||
|
|
||
| Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| require 'capybara-screenshot/rspec' | ||
|
|
||
| Capybara::Screenshot.autosave_on_failure = true | ||
| Capybara::Screenshot.prune_strategy = { keep: 20 } | ||
|
|
||
| RSpec.configure do |config| | ||
| # Not just for type: :feature | ||
| config.after do |example_from_block_arg| | ||
| # RSpec 3 no longer defines `example`, but passes the example as block argument instead | ||
| example = config.respond_to?(:expose_current_running_example_as) ? example_from_block_arg : self.example | ||
|
|
||
| if example.exception && ENV['CI'] | ||
| puts page.html | ||
| end | ||
| Capybara::Screenshot::RSpec.after_failed_example(example) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe Xray, "in a Rails app (end-to-end)", :js do | ||
| it "works" do | ||
| visit '/' | ||
| expect_to_work | ||
| end | ||
|
|
||
| if Gem.loaded_specs['rails'].version >= Gem::Version.new('5.2.0') | ||
| it "works when using a strict CSP" do | ||
| visit '/strict_csp' | ||
| expect_to_work | ||
| end | ||
| end | ||
|
|
||
| def expect_to_work | ||
| if Gem.loaded_specs['rails'].version >= Gem::Version.new('5.2.0') | ||
| expect(page).to have_selector('script[src^="/assets/xray"][nonce]') | ||
| expect(page.find('script[src^="/assets/xray"]')[:nonce]).to eq page.find('meta[name="csp-nonce"]')[:content] | ||
| end | ||
| expect(page).to have_selector('#xray-bar') | ||
|
|
||
| expect(page).to have_no_selector('.xray-specimen-handle.TemplateSpecimen', text: 'root.html.erb') | ||
| find('body').send_keys [:control, :shift, 'x'] | ||
| expect(page).to have_selector('.xray-specimen-handle.TemplateSpecimen', text: 'root.html.erb') | ||
| end | ||
| end unless ENV['CI'] == 'true' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.