fix(security): migrate webhook auth to HMAC-SHA256 signature header#970
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the security posture of the HTTP webhook channel by upgrading its authentication mechanism. Instead of relying on a secret embedded directly in the request body, it now leverages HMAC-SHA256 signatures provided in a dedicated header. This change enhances the integrity and authenticity of incoming webhook requests, making the system more robust against tampering. A temporary fallback for the old authentication method is included to ease migration, alongside new input validations for request headers and content. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a solid security enhancement, migrating webhook authentication from a simple secret in the request body to a more robust HMAC-SHA256 signature in the headers. The implementation correctly maintains backward compatibility and includes a comprehensive set of tests for the new logic. My review includes a couple of suggestions to improve code clarity and maintainability.
| let mut mac = match HmacSha256::new_from_slice(secret.as_bytes()) { | ||
| Ok(mac) => mac, | ||
| Err(_) => return false, | ||
| }; |
There was a problem hiding this comment.
The HmacSha256::new_from_slice method for Hmac from the hmac crate is guaranteed not to fail (it always returns Ok). Therefore, this match statement contains an unreachable Err arm. You can simplify this to a single line using .unwrap() to make the code more concise and signal that this operation is considered infallible. A panic here would indicate a breaking change in the dependency, which is a condition you'd want to fail fast on.
let mut mac = HmacSha256::new_from_slice(secret.as_bytes()).unwrap();| return ( | ||
| StatusCode::UNAUTHORIZED, | ||
| Json(WebhookResponse { | ||
| message_id: Uuid::nil(), | ||
| status: "error".to_string(), | ||
| response: Some("Invalid webhook signature".to_string()), | ||
| }), | ||
| ) | ||
| .into_response(); |
There was a problem hiding this comment.
This pattern of creating a Json(WebhookResponse { ... }) for error responses is repeated multiple times in this function for different error conditions (e.g., rate limiting, invalid content type, various auth failures). To improve readability and reduce code duplication, consider extracting this into a helper function. For example, a function like fn unauthorized_response(message: &str) -> axum::response::Response could encapsulate this logic, making the main handler flow easier to follow.
References
- This comment aligns with the guideline to refactor duplicated code into a shared function to improve readability and reduce redundancy.
Summary
X-IronClaw-SignatureHMAC-SHA256 verificationWhy this replacement PR exists
The original approved PR #513 is on a branch I cannot update directly from this checkout, so this branch cleanly reapplies the approved change on top of current
staging.Validation
cargo test channels::http::tests::