lib/rollbar/middleware/js.rb in rollbar-2.19.2 vs lib/rollbar/middleware/js.rb in rollbar-2.19.3
- old
+ new
@@ -11,11 +11,11 @@
include Rollbar::RequestDataExtractor
attr_reader :app
attr_reader :config
- JS_IS_INJECTED_KEY = 'rollbar.js_is_injected'
+ JS_IS_INJECTED_KEY = 'rollbar.js_is_injected'.freeze
SNIPPET = File.read(File.expand_path('../../../../data/rollbar.snippet.js', __FILE__))
def initialize(app, config)
@app = app
@config = config
@@ -27,11 +27,11 @@
begin
return app_result unless add_js?(env, app_result[1])
response_string = add_js(env, app_result[2])
build_response(env, app_result, response_string)
- rescue => e
+ rescue StandardError => e
Rollbar.log_error("[Rollbar] Rollbar.js could not be added because #{e} exception")
app_result
end
end
@@ -69,11 +69,11 @@
insert_after_idx = find_insertion_point(body)
return nil unless insert_after_idx
build_body_with_js(env, body, insert_after_idx)
- rescue => e
+ rescue StandardError => e
Rollbar.log_error("[Rollbar] Rollbar.js could not be added because #{e} exception")
nil
end
def build_response(env, app_result, response_string)
@@ -187,21 +187,21 @@
config = ::SecureHeaders::Configuration
secure_headers_cls = nil
- if !::SecureHeaders::respond_to?(:content_security_policy_script_nonce)
- secure_headers_cls = SecureHeadersFalse
- elsif config.respond_to?(:get)
- secure_headers_cls = SecureHeaders3To5
- elsif config.dup.respond_to?(:csp)
- secure_headers_cls = SecureHeaders6
- else
- secure_headers_cls = SecureHeadersFalse
- end
+ secure_headers_cls = if !::SecureHeaders.respond_to?(:content_security_policy_script_nonce)
+ SecureHeadersFalse
+ elsif config.respond_to?(:get)
+ SecureHeaders3To5
+ elsif config.dup.respond_to?(:csp)
+ SecureHeaders6
+ else
+ SecureHeadersFalse
+ end
- secure_headers_cls.new
+ secure_headers_cls.new
end
class SecureHeadersResolver
def append_nonce?
csp_needs_nonce?(find_csp)
@@ -215,10 +215,10 @@
def csp_needs_nonce?(csp)
!opt_out?(csp) && !unsafe_inline?(csp)
end
- def opt_out?(csp)
+ def opt_out?(_csp)
raise NotImplementedError
end
def unsafe_inline?(csp)
csp[:script_src].to_a.include?("'unsafe-inline'")