Sha256: db6bf15f6f853080498d4d382463facf93241c905cab9d2f4e97e87e1616cca6

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true
module GoodJob
  class BaseController < ActionController::Base # rubocop:disable Rails/ApplicationController
    protect_from_forgery with: :exception

    around_action :switch_locale

    content_security_policy do |policy|
      policy.default_src(:none) if policy.default_src.blank?
      policy.connect_src(:self) if policy.connect_src.blank?
      policy.base_uri(:none) if policy.base_uri.blank?
      policy.font_src(:self) if policy.font_src.blank?
      policy.img_src(:self, :data) if policy.img_src.blank?
      policy.object_src(:none) if policy.object_src.blank?
      policy.script_src(:self) if policy.script_src.blank?
      policy.style_src(:self) if policy.style_src.blank?
      policy.form_action(:self) if policy.form_action.blank?
      policy.frame_ancestors(:none) if policy.frame_ancestors.blank?
    end

    before_action do
      next if request.content_security_policy_nonce_generator

      request.content_security_policy_nonce_generator = ->(_request) { SecureRandom.base64(16) }
    end

    private

    def switch_locale(&action)
      I18n.with_locale(:en, &action)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
good_job-2.7.0 engine/app/controllers/good_job/base_controller.rb