Security audit: Fix critical authentication bypass and class injection vulnerabilities#10
Conversation
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
…ehensive security tests Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR strengthens security around authentication and handler loading by enforcing stricter configuration validation, sanitization, and class loading checks.
- Enforces presence and completeness of authentication config in
validate_auth!, with generic error messages to avoid information disclosure. - Implements whitelist-based handler name validation, directory traversal prevention, and inheritance checks in both the config validator and
load_handler. - Adds comprehensive security-focused specs for auth validators, endpoint config validation, and handler loading.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/hooks/app/auth/auth.rb | Added checks for auth type and secret_env_key presence and generic error msgs |
| lib/hooks/app/helpers.rb | Added valid_handler_class_name?, path traversal prevention, and inheritance checks |
| lib/hooks/core/config_validator.rb | Introduced valid_handler_name? and integrated it into endpoint validation |
| spec/unit/lib/hooks/plugins/auth/security_validators_spec.rb | New security tests for HMAC and SharedSecret validators |
| spec/unit/lib/hooks/core/config_validator_security_spec.rb | New security tests for endpoint config validation |
| spec/unit/lib/hooks/app/helpers_security_spec.rb | New security tests for handler loading |
| spec/unit/lib/hooks/app/auth/auth_security_spec.rb | New security tests for validate_auth! |
| return false unless class_name.match?(/\A[A-Z][a-zA-Z0-9_]*\z/) | ||
|
|
||
| # Must not be a system/built-in class name | ||
| dangerous_classes = %w[ |
There was a problem hiding this comment.
[nitpick] The dangerous_classes list is duplicated in both helpers and the config validator. Extract this list into a shared constant or module to adhere to DRY and simplify future updates.
| dangerous_classes = %w[ | ||
| File Dir Kernel Object Class Module Proc Method | ||
| IO Socket TCPSocket UDPSocket BasicSocket | ||
| Process Thread Fiber Mutex ConditionVariable | ||
| Marshal YAML JSON Pathname | ||
| ] | ||
| return false if dangerous_classes.include?(handler_name) |
There was a problem hiding this comment.
[nitpick] This dangerous_classes array mirrors the one in Helpers. Consider extracting it into a shared constant to avoid duplication and ensure consistency.
| dangerous_classes = %w[ | |
| File Dir Kernel Object Class Module Proc Method | |
| IO Socket TCPSocket UDPSocket BasicSocket | |
| Process Thread Fiber Mutex ConditionVariable | |
| Marshal YAML JSON Pathname | |
| ] | |
| return false if dangerous_classes.include?(handler_name) | |
| return false if DANGEROUS_CLASSES.include?(handler_name) |
|
|
||
| # Security: Ensure auth type is present and valid | ||
| unless auth_config&.dig(:type)&.is_a?(String) | ||
| error!("authentication configuration missing or invalid", 500) |
There was a problem hiding this comment.
[nitpick] Client-side configuration errors (e.g., missing or invalid auth config) are more appropriately represented with a 400 series status code. Consider using 400 instead of 500 for these checks.
| error!("authentication configuration missing or invalid", 500) | |
| error!("authentication configuration missing or invalid", 400) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This PR addresses critical security vulnerabilities found during a comprehensive security audit of the webhook server framework's authentication and handler loading mechanisms.
Critical Vulnerabilities Fixed
1. Authentication Bypass (CVE-level severity)
Issue: Missing
secret_env_keyin endpoint configuration completely bypassed authentication validation, allowing unauthenticated requests to be processed.Fix: Enhanced
validate_auth!to require proper authentication configuration and reject incomplete auth setups.2. Dynamic Class Loading Vulnerability (RCE Risk)
Issue: Handler names from configuration were passed directly to
Object.const_get(), enabling arbitrary class instantiation and potential remote code execution.Fix:
Hooks::Handlers::Base3. Information Disclosure
Issue: Error messages leaked environment variable names, potentially revealing sensitive configuration details.
Security Enhancements
Authentication Hardening
Handler Security
Input Validation
/\A[A-Z][a-zA-Z0-9_]*\z/Test Coverage
Added 42 new security-focused test cases covering:
Files Changed
lib/hooks/app/auth/auth.rb: Fixed authentication bypass vulnerabilitylib/hooks/app/helpers.rb: Secured dynamic handler loadinglib/hooks/core/config_validator.rb: Added handler name validationVerification
All security tests pass and the framework maintains 81%+ test coverage. The fixes are minimal and focused, preserving existing functionality while closing critical security gaps.
Security Impact: These fixes prevent potential remote code execution, authentication bypass, and information disclosure vulnerabilities that could compromise webhook server deployments.
Fixes #9.