Last active
April 20, 2020 21:51
-
-
Save oreoshake/994f547ad542c5d2d513ab315b03eead to your computer and use it in GitHub Desktop.
secure_headers basic use
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
class ApplicationController < ActionController::Base | |
def add_csp_exceptions | |
append_content_security_policy_directives(self.class::CSP_EXCEPTIONS) | |
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
class ExampleController < ApplicationController | |
CSP_EXCEPTIONS = { | |
frame_src: ["foo.com"], | |
} | |
before_action :add_csp_exceptions, only: :show | |
def index | |
# doesn't get the additonal allowance | |
end | |
def show | |
# gets foo.com appended to the current frame_src value | |
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
class OtherController < ApplicationController | |
def index | |
if feature_enabled? | |
append_content_security_policy_directives(connect_src: [THIRD_PARTY]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment