Enhance HMAC auth plugin to support structured signature headers (Tailscale-style)#52
Merged
Conversation
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] task: make the hmac auth plugin even more flexible
Enhance HMAC auth plugin to support structured signature headers (Tailscale-style)
Jun 17, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for structured signature headers (Tailscale-style) to the HMAC auth plugin, while preserving full backward compatibility.
- Introduces
parse_structured_headerand integrates structured header handling into the HMAC validation flow. - Extends default config and
build_configto includeheader_format,signature_key, andtimestamp_key. - Adds unit tests for parsing and validating structured headers.
- Updates documentation with new configuration options and Tailscale examples.
Reviewed Changes
Copilot reviewed 10 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| spec/unit/lib/hooks/plugins/auth/hmac_spec.rb | Added tests for parse_structured_header and structured-header validation |
| lib/hooks/plugins/auth/hmac.rb | Implemented structured-header parsing and integrated in valid? |
| docs/auth_plugins.md | Documented header_format, signature_key, timestamp_key and Tailscale example |
| .bundle/config | Bundler path settings updated (CI-specific, should be reverted) |
Comments suppressed due to low confidence (2)
lib/hooks/plugins/auth/hmac.rb:38
- [nitpick] The inline example uses
type: HMAC(uppercase) but elsewhere the plugin type is specified in lowercase (hmac). For consistency, update this example totype: hmac.
# type: HMAC
.bundle/config:3
- This file includes CI-specific Bundler paths that should not be committed. Revert or remove these changes to avoid breaking local development environments.
BUNDLE_PATH: "/home/runner/work/hooks/hooks/vendor/bundle"
…lt hmac auth plugin
- Introduced MAX_HEADER_VALUE_LENGTH and MAX_PAYLOAD_SIZE constants for validation. - Implemented header and payload size validation methods in Base class. - Updated HMAC and SharedSecret validators to utilize new validation methods. - Added tests for oversized headers and payloads to ensure compliance with limits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The HMAC auth plugin now supports providers like Tailscale that use structured signature headers with comma-separated key-value pairs, while maintaining full backward compatibility with existing webhook providers.
Problem
The existing HMAC plugin supported various webhook providers (GitHub, GitLab, Shopify, Slack) but couldn't handle providers like Tailscale that use:
t=1663781880,v1=0123456789abcdef{timestamp}.{body}Solution
Added minimal, backward-compatible enhancements to support structured headers:
New Configuration Options
header_format: "structured"- Enables parsing of comma-separated key-value pairssignature_key: "v1"- Configurable key name for signature in structured headertimestamp_key: "t"- Configurable key name for timestamp in structured headerpayload_templateto support dot-separated formatExample: Tailscale Configuration
How It Works
t=1663781880,v1=abc123...→ Extract timestamp and signature{timestamp}.{body}→1663781880.{"event":"test"}Testing & Quality
Security
Backward Compatibility
All existing webhook configurations continue to work unchanged:
X-Hub-Signature-256: sha256=abc123...X-Gitlab-Token: sha256=abc123...X-Shopify-Hmac-Sha256: abc123...X-Slack-Signature: v0=abc123...Documentation
docs/auth_plugins.mdThis enhancement makes the hooks framework significantly more versatile for webhook processing across different provider ecosystems without breaking any existing functionality.
Fixes #51.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.