Skip to content

Commit

Permalink
feat: allow rack protection use and except options to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 14, 2022
1 parent e9a66b9 commit f44db58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/pact_broker/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,14 @@ def configure_basic_auth

def configure_rack_protection
if configuration.use_rack_protection
@app_builder.use Rack::Protection, except: [:path_traversal, :remote_token, :session_hijacking, :http_origin]
rack_protection_options = {
logger: logger,
use: configuration.rack_protection_use,
except: configuration.rack_protection_except
}.compact

logger.info("Configuring Rack::Protection", payload: rack_protection_options)
@app_builder.use Rack::Protection, rack_protection_options

is_hal_browser = ->(env) { env["PATH_INFO"] == "/hal-browser/browser.html" }
not_hal_browser = ->(env) { env["PATH_INFO"] != "/hal-browser/browser.html" }
Expand Down
10 changes: 10 additions & 0 deletions lib/pact_broker/config/runtime_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class RuntimeConfiguration < Anyway::Config
use_hal_browser: true,
enable_diagnostic_endpoints: true,
use_rack_protection: true,
rack_protection_use: nil,
rack_protection_except: [:path_traversal, :remote_token, :session_hijacking, :http_origin], # Beth: not sure why these are disabled
badge_provider_mode: :redirect,
enable_public_badge_access: false,
shields_io_base_url: "https://img.shields.io",
Expand Down Expand Up @@ -180,6 +182,14 @@ def features= features
super(value_to_string_array(features, "features").collect(&:downcase))
end

def rack_protection_use= rack_protection_use
super(value_to_string_array(rack_protection_use, "rack_protection_use")&.collect(&:to_sym))
end

def rack_protection_except= rack_protection_except
super(value_to_string_array(rack_protection_except, "rack_protection_except")&.collect(&:to_sym))
end

def webhook_certificates= webhook_certificates
if webhook_certificates.is_a?(Array)
super(webhook_certificates.collect(&:symbolize_keys))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Config
:warning_error_class_names,
:log_configuration_on_startup,
:use_rack_protection,
:rack_protection_use,
:rack_protection_except,
:use_case_sensitive_resource_names,
:order_versions_by_date,
:base_equality_only_on_content_that_affects_verification_results,
Expand Down

0 comments on commit f44db58

Please sign in to comment.