Skip to content

Instantly share code, notes, and snippets.

@oreoshake
Last active April 20, 2020 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oreoshake/994f547ad542c5d2d513ab315b03eead to your computer and use it in GitHub Desktop.
Save oreoshake/994f547ad542c5d2d513ab315b03eead to your computer and use it in GitHub Desktop.
secure_headers basic use
class ApplicationController < ActionController::Base
def add_csp_exceptions
append_content_security_policy_directives(self.class::CSP_EXCEPTIONS)
end
end
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
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