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

Allow adding/removing of existing Content-Security-Policy and Permissions-Policy directives #46859

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

agrobbin
Copy link
Contributor

Motivation / Background

Previously, if you wanted to add/remove directives from either header, you had to redefine the defaults in the controller.

Rails.application.configure do
  config.content_security_policy do |policy|
    policy.default_src :none

    policy.script_src :self, 'a.com', 'b.com'
  end
end

class FooController < ApplicationController
  content_security_policy do |policy|
    policy.script_src :self, 'a.com', 'b.com', 'c.com'
  end
end

Detail

Now, you can adjust the policy directives without overwriting the global configuration.

Rails.application.configure do
  config.content_security_policy do |policy|
    policy.default_src :none

    policy.script_src :self, 'a.com', 'b.com'
  end
end

class FooController < ApplicationController
  content_security_policy do |policy|
    policy.add_script_src 'c.com'
  end
end

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@agrobbin agrobbin force-pushed the content-security-policy-add-remove branch 4 times, most recently from beacaca to ebf7126 Compare December 30, 2022 02:43
@agrobbin agrobbin force-pushed the content-security-policy-add-remove branch 2 times, most recently from 2a92cf8 to 4ba5490 Compare January 6, 2023 00:11
@agrobbin agrobbin force-pushed the content-security-policy-add-remove branch from 4ba5490 to e2b26f9 Compare February 3, 2023 19:12
@agrobbin
Copy link
Contributor Author

agrobbin commented Feb 3, 2023

If/when someone from the Core team has a few minutes, it'd be great to get a review! I'd love to get something like this into Rails.

…issions-Policy` directives.

Previously, if you wanted to add/remove directives from either header, you had to redefine the defaults in the controller.

Now, you can adjust the policy directives without overwriting the global configuration.
@agrobbin agrobbin force-pushed the content-security-policy-add-remove branch from e2b26f9 to 03ca950 Compare April 22, 2023 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant