66
77module Hooks
88 module Plugins
9- module RequestValidator
9+ module Auth
1010 # Generic HMAC signature validator for webhooks
1111 #
1212 # This validator supports multiple webhook providers with different signature formats.
1313 # It provides flexible configuration options to handle various HMAC-based authentication schemes.
1414 #
1515 # @example Basic configuration with algorithm prefix
16- # request_validator :
16+ # auth :
1717 # type: HMAC
1818 # secret_env_key: WEBHOOK_SECRET
1919 # header: X-Hub-Signature-256
2020 # algorithm: sha256
2121 # format: "algorithm=signature"
2222 #
2323 # @example Configuration with timestamp validation
24- # request_validator :
24+ # auth :
2525 # type: HMAC
2626 # secret_env_key: WEBHOOK_SECRET
2727 # header: X-Signature
@@ -66,7 +66,7 @@ class HMAC < Base
6666 # @param headers [Hash<String, String>] HTTP headers from the request
6767 # @param secret [String] Secret key for HMAC computation
6868 # @param config [Hash] Endpoint configuration containing validator settings
69- # @option config [Hash] :request_validator Validator-specific configuration
69+ # @option config [Hash] :auth Validator-specific configuration
7070 # @option config [String] :header ('X-Signature') Header containing the signature
7171 # @option config [String] :timestamp_header Header containing timestamp (optional)
7272 # @option config [Integer] :timestamp_tolerance (300) Timestamp tolerance in seconds
@@ -83,7 +83,7 @@ class HMAC < Base
8383 # payload: request_body,
8484 # headers: request.headers,
8585 # secret: ENV['WEBHOOK_SECRET'],
86- # config: { request_validator : { header: 'X-Signature' } }
86+ # config: { auth : { header: 'X-Signature' } }
8787 # )
8888 def self . valid? ( payload :, headers :, secret :, config :)
8989 return false if secret . nil? || secret . empty?
@@ -131,8 +131,8 @@ def self.valid?(payload:, headers:, secret:, config:)
131131
132132 # Use secure comparison to prevent timing attacks
133133 Rack ::Utils . secure_compare ( computed_signature , provided_signature )
134- rescue StandardError => _e
135- # Log error in production - for now just return false
134+ rescue StandardError => e
135+ log . error ( "Auth::HMAC validation failed: #{ e . message } " )
136136 false
137137 end
138138
@@ -148,7 +148,7 @@ def self.valid?(payload:, headers:, secret:, config:)
148148 # @note Missing configuration values are filled with DEFAULT_CONFIG values
149149 # @api private
150150 def self . build_config ( config )
151- validator_config = config . dig ( :request_validator ) || { }
151+ validator_config = config . dig ( :auth ) || { }
152152
153153 algorithm = validator_config [ :algorithm ] || DEFAULT_CONFIG [ :algorithm ]
154154 tolerance = validator_config [ :timestamp_tolerance ] || DEFAULT_CONFIG [ :timestamp_tolerance ]
0 commit comments