-
Notifications
You must be signed in to change notification settings - Fork 0
Security audit: Fix information disclosure, enhance logging, and optimize auth plugins #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: GrantBirki <[email protected]>
…der matching Co-authored-by: GrantBirki <[email protected]>
Co-authored-by: GrantBirki <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR secures and refactors the webhook authentication flow by sanitizing error messages, adding detailed logging, and extracting common header lookup for performance and maintainability.
- Sanitize sensitive environment keys in
fetch_secret
error messages - Add debug/warn/error logging to SharedSecret & HMAC validations
- Introduce a reusable
find_header_value
to eliminate header‐iteration duplication
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
lib/hooks/plugins/auth/base.rb | Sanitize fetch_secret errors; add public find_header_value |
lib/hooks/plugins/auth/shared_secret.rb | Integrate find_header_value ; add logging branches |
lib/hooks/plugins/auth/hmac.rb | Integrate find_header_value ; add logging branches |
spec/unit/lib/hooks/plugins/auth/base_spec.rb | Updated interface tests; added find_header_value specs |
spec/unit/lib/hooks/plugins/auth/shared_secret_spec.rb | Added tests for successful debug and warning/error logging |
spec/unit/lib/hooks/plugins/auth/hmac_spec.rb | Added tests for successful debug and warning logging |
.bundle/config | Updated bundler paths for CI deployment |
Comments suppressed due to low confidence (4)
spec/unit/lib/hooks/plugins/auth/shared_secret_spec.rb:363
- Add tests for invalid headers (e.g., passing nil or a non-enumerable) to ensure
valid?
logs a warning and returns false.
context "Debug and warning logging coverage" do
spec/unit/lib/hooks/plugins/auth/shared_secret_spec.rb:363
- Add specs covering missing/empty secret header, leading/trailing whitespace, and control-character rejection to exercise all logging branches.
context "Debug and warning logging coverage" do
spec/unit/lib/hooks/plugins/auth/hmac_spec.rb:654
- Include tests for invalid headers object (nil or non-hash) and empty/missing signature header to validate warning branches.
describe "debug and warning logging" do
spec/unit/lib/hooks/plugins/auth/hmac_spec.rb:654
- Add specs for signature containing leading/trailing whitespace and control characters to cover all reject conditions.
describe "debug and warning logging" do
@@ -1,5 +1,7 @@ | |||
# frozen_string_literal: true | |||
|
|||
require_relative "../../../../spec_helper" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Switch to the project-standard require "spec_helper"
to keep spec files consistent and avoid deep relative paths.
require_relative "../../../../spec_helper" | |
require "spec_helper" |
Copilot uses AI. Check for mistakes.
.bundle/config
Outdated
@@ -1,7 +1,8 @@ | |||
--- | |||
BUNDLE_BIN: "bin" | |||
BUNDLE_PATH: "vendor/gems" | |||
BUNDLE_PATH: "/home/runner/work/hooks/hooks/vendor/bundle" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Committing CI-specific absolute paths can break local setups; consider using a relative or environment-agnostic path.
BUNDLE_PATH: "/home/runner/work/hooks/hooks/vendor/bundle" | |
BUNDLE_PATH: "<%= ENV['BUNDLE_PATH'] || 'vendor/bundle' %>" |
Copilot uses AI. Check for mistakes.
This PR addresses the comprehensive security audit requested in the issue, focusing on the shared secret and HMAC authentication components.
Security Vulnerabilities Fixed
1. Information Disclosure in Error Messages
Issue: The
Base.fetch_secret
method was exposing sensitive environment variable key names in error messages, potentially leaking configuration details in logs.Fix: Sanitized error messages to remove sensitive information while maintaining useful debugging context.
2. Enhanced Security Monitoring
Issue: Limited visibility into authentication failures made it difficult to detect potential security issues or attacks.
Fix: Added comprehensive debug and warning logging throughout the authentication flow:
Performance & Code Quality Improvements
3. Eliminated Code Duplication
Issue: Both HMAC and SharedSecret classes had nearly identical header matching logic, leading to maintenance overhead and potential inconsistencies.
Fix: Extracted common functionality into a reusable
Base.find_header_value
method:4. Performance Optimization
Issue: Both authentication classes were iterating through all headers for each validation, which is inefficient for requests with many headers.
Fix: Consolidated header lookup logic and eliminated redundant iterations.
5. Code Cleanup
_payload:
)Security Assessment Summary
✅ No hardcoded secrets or credentials found
✅ All authentication methods use secure comparison (timing attack prevention)
✅ Proper input validation and sanitization implemented
✅ Enhanced logging without exposing sensitive data
✅ No unused or redundant authentication code identified
✅ Performance optimizations maintain security guarantees
Testing
These changes significantly improve the security posture of the webhook authentication system while maintaining backward compatibility and improving monitoring capabilities for potential security incidents.
Fixes #45.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.