-
-
Notifications
You must be signed in to change notification settings - Fork 0
Use secret key for token middleware signatures #84
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
Use secret key for token middleware signatures #84
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughToken middleware verification switches local signature computation to use token.SecretKey. Corresponding tests now sign requests with seed.SecretKey instead of seed.PublicKey. Test helper parameters and calls are updated to reflect secret-based signing. No public APIs changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant M as TokenMiddleware
participant S as SignatureVerifier
C->>M: HTTP request with headers<br/>X-API-Key, X-API-Nonce, X-API-Signature
M->>M: Canonicalize request
M->>S: Compute local HMAC using token.SecretKey
S-->>M: localSignature
M->>M: Constant-time compare(localSignature, headerSignature)
alt Signature valid and nonce fresh
M-->>C: Forward to next handler
else Signature invalid or nonce replay
M-->>C: 401/403 error response
end
note over M,S: Change: use SecretKey for local signature computation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (3)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Summary of Changes
Hello @gocanto, 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 implements a critical security enhancement by modifying the token authentication middleware to use a secret key for generating and verifying request signatures. Previously, the public key was mistakenly used for this purpose. The change ensures that the integrity of incoming requests is validated against a private credential, significantly strengthening the authentication mechanism. The accompanying test updates validate this new secure behavior.
Highlights
- Security Enhancement: The token middleware now correctly uses the
SecretKeyinstead of thePublicKeyto compute the local signature for canonical requests, significantly improving the security of token validation. - Test Suite Update: All relevant test cases across
token_middleware_additional_test.goandtoken_middleware_test.gohave been updated to reflect this change, ensuring that requests are signed with theSecretKeyin tests.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request correctly addresses a critical security vulnerability by using the secret key for signing and verifying API requests, instead of the public key. The change is implemented correctly in the middleware, and all associated tests have been updated to reflect this new logic. I've included a few minor comments regarding code formatting to ensure consistency with Go standards.
| // Compute local signature over canonical request using the account's secret key | ||
| // and compare in constant time (hash to fixed-length first) | ||
| localSignature := auth.CreateSignatureFrom(canonical, token.SecretKey) |
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.
The indentation for these new lines appears to be using spaces instead of tabs. The standard Go format (gofmt) uses tabs for indentation. Please run gofmt on the file to fix the formatting for consistency.
| // Compute local signature over canonical request using the account's secret key | |
| // and compare in constant time (hash to fixed-length first) | |
| localSignature := auth.CreateSignatureFrom(canonical, token.SecretKey) | |
| // Compute local signature over canonical request using the account's secret key | |
| // and compare in constant time (hash to fixed-length first) | |
| localSignature := auth.CreateSignatureFrom(canonical, token.SecretKey) |
| handler := tm.Handle(next) | ||
|
|
||
| req := makeSignedRequest(t, http.MethodGet, "https://api.test.local/v1/x", "", seed.AccountName, "wrong-"+seed.PublicKey, seed.SecretKey, time.Now(), "nonce-mm", "req-mm") | ||
| req := makeSignedRequest(t, http.MethodGet, "https://api.test.local/v1/x", "", seed.AccountName, "wrong-"+seed.PublicKey, seed.SecretKey, time.Now(), "nonce-mm", "req-mm") |
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.
This line is indented with spaces instead of tabs. Please run gofmt on this file to ensure consistent formatting with the rest of the codebase. This issue is present on other new lines in this file as well.
| req := makeSignedRequest(t, http.MethodGet, "https://api.test.local/v1/x", "", seed.AccountName, "wrong-"+seed.PublicKey, seed.SecretKey, time.Now(), "nonce-mm", "req-mm") | |
| req := makeSignedRequest(t, http.MethodGet, "https://api.test.local/v1/x", "", seed.AccountName, "wrong-"+seed.PublicKey, seed.SecretKey, time.Now(), "nonce-mm", "req-mm") |
| canonical := portal.BuildCanonical(method, req.URL, account, public, req.Header.Get("X-API-Timestamp"), nonce, bodyHash) | ||
| sig := auth.CreateSignatureFrom(canonical, secret) |
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.
These lines are indented with spaces instead of tabs. Please run gofmt on this file to ensure consistent formatting. This issue appears on other new lines in this file as well.
| canonical := portal.BuildCanonical(method, req.URL, account, public, req.Header.Get("X-API-Timestamp"), nonce, bodyHash) | |
| sig := auth.CreateSignatureFrom(canonical, secret) | |
| canonical := portal.BuildCanonical(method, req.URL, account, public, req.Header.Get("X-API-Timestamp"), nonce, bodyHash) | |
| sig := auth.CreateSignatureFrom(canonical, secret) |
Summary
Testing
go test ./... -count=1https://chatgpt.com/codex/tasks/task_e_68baab767e7083338f0d513251f1e73e
Summary by CodeRabbit