-
Notifications
You must be signed in to change notification settings - Fork 598
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
Rails CSP nonce auto inject #2544
Conversation
I'v submitted this to have your opinion for this feature. the code is not ready, that's just something like a monkey patch I did in my code to have this working without disabling the I think, with some more work and tests we could have this working for rails and other frameworks as well! |
Hi @baldarn! Thanks for sharing your idea with us! ✨ I'll bring this up with the other maintainers and get back to you soon! |
Hi @baldarn, the maintainers agree and we'd like to move forward with your idea! Thank you for your contribution! 🚀 As you mentioned earlier, we'll need tests, etc. before including this in a release, but that's something we could handle if you want to stop here. What next steps would you like to take? |
Great news! I'll try to do something. I have 2 options in my mind, but I first have to try to do some code ;) |
adding csp configuration for rails after 5.2 default_value to enable csp nonce set to false
@kaylareopelle I did something but I'm struggling to add the tests. maybe you can point me the right direction or just commit something that tests the code? It's also not super clear how the configuration works, I added something in |
Thanks, @baldarn! This looks great! Your instincts were spot on with adding a configuration to We can take care of the tests, thanks for updating the environments! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few suggestions before approval. Thanks again for you contribution!
test/environments/rails52/config/initializers/content_security_policy.rb
Outdated
Show resolved
Hide resolved
Co-authored-by: Kayla Reopelle (she/her) <87386821+kaylareopelle@users.noreply.github.com>
After the PR is merged, this doc should also be updated ;) https://docs.newrelic.com/docs/apm/agents/ruby-agent/features/new-relic-browser-ruby-agent/ (to avoid forgetting, I added a check list in the PR description ;) ) |
- Defined a dedicated `nonce` method for the nonce logic - Added unit tests to confirm a nonce is or isn't added to the output
Hi @baldarn! With dd5cc7b I have gone ahead and added some simple unit tests to verify the nonce/no-nonce logic you established. I think these unit tests are sufficient for now. As such, would you please As for the changes to I think after you do those 2 things (delete the Rails initializer files, remove the content from |
@fallwith done |
guard against `ActionDispatch` and `Rails` not being defined. in the tests, the `norails` suite reaches the nonce tests, so skip them
Thanks, @baldarn. Everything looks great. We can ignore the "unit_tests" test failures as those exist in Regarding your suggested documentation update... the text for that page is in a different open source repo here. We can't apply changes there until the changes here have made their way into a new agent release. We will make a note of it for our next release, but if you don't see that page get changed after we next release a new agent version, please feel free to reach out back here or on the docs repo with a new GitHub issue to remind us. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for these changes, @baldarn! They will go out in the next version of the Ruby agent.
Hi @baldarn! I wanted to let you know this change is part of I've also updated the browser docs to mention this feature. If there's anything you'd like to see changed about this doc, on the righthand pane, there's an option to edit the doc. This will take you to the New Relic docs-website repository to make changes to the file. Thanks again for your contribution! |
Hi @kaylareopelle , this was a pleasure xD In the doc is written that this default is default I don't understand well the config file XD |
@baldarn, thank you for this catch! 😅 You're absolutely right, the default is |
We just updated to 9.10 and we didn't change the
I am confused now 😓 |
@sgessa, you're totally right. Thanks for chiming in here. 🙇 Our config can get a little tricky, especially when there's dynamic values at play. What happened was I looked at the We're reverting the changelog updates made this morning and fortunately caught the docs PR before it was merged. This has made for an exciting Friday! Let us know if you run into any issues with the new feature. |
Overview
The idea is to allow apps with
auto_instrument: true
and CSP with nonce enforced to still have newrelic workingSubmitter Checklist:
newrelic & sidekiq 7.2.1 agent injection not working? #2427
Testing
The agent includes a suite of unit and functional tests which should be used to
verify your changes don't break existing functionality. These tests will run with
GitHub Actions when a pull request is made. More details on running the tests locally can be found
here for our unit tests,
and here for our functional tests.
For most contributions it is strongly recommended to add additional tests which
exercise your changes.
Reviewer Checklist