-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix Feishu webhook signature verification #34788
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
@techknowlogick All errors fixed |
**Performance Overhead** `fmt.Sprintf` is **slower** than simple string concatenation or `strconv.FormatInt` because: * It uses reflection and parsing logic internally. * It's designed for formatting many types, not just basic strings or numbers. Co-Authored-By: hiifong <[email protected]>
Added a test (the test data is generated by Feishu python demo), and simplified the code a little |
@wxiaoguang Sorry, due to a funny problem, one of your commit(probably called 'change a better name') was reverted. Please push your code again. |
Done. Hopefully the updated code looks good to you. Thank you very much for the PR |
# Fix Feishu Webhook Signature Verification This PR implements proper signature verification for Feishu (Lark) webhooks according to the [official documentation](https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot). ## Changes - Implemented the `GenSign` function based on Feishu's official Go sample code - Modified the webhook request creation to include timestamp and signature in the payload when a secret is configured - Fixed the signature generation algorithm to properly use HMAC-SHA256 with the correct string format ## Implementation Details The signature verification works as follows: 1. When a webhook secret is provided, a timestamp is generated 2. The signature string is created using `timestamp + "\n" + secret` 3. The HMAC-SHA256 algorithm is applied to an empty string using the signature string as the key 4. The result is Base64 encoded to produce the final signature 5. Both timestamp and signature are added to the payload According to Feishu's documentation, the timestamp must be within 1 hour (3600 seconds) of the current time to be considered valid. ## Security Note Feishu emphasizes the importance of keeping webhook URLs secure. Do not disclose them on GitHub, blogs, or any public sites to prevent unauthorized use. ## References - [Feishu Custom Bot Documentation](https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot) --------- Co-authored-by: hiifong <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
Found that the fix is incomplete, there is no "Secret" input on the UI |
* giteaofficial/main: (22 commits) [skip ci] Updated translations via Crowdin Fix required contexts and commit status matching bug (go-gitea#34815) Add "Cancel workflow run" button to Actions list page (go-gitea#34817) Use `shallowRef` instead of `ref` in `.vue` files where possible (go-gitea#34813) Edit file workflow for creating a fork and proposing changes (go-gitea#34240) Refactor packages (go-gitea#34777) Refactor wiki (go-gitea#34805) [skip ci] Updated translations via Crowdin Upgrade htmx to 2.0.5 (go-gitea#34809) Forks repository list page follow other repositories page (go-gitea#34784) Add post-installation redirect based on admin account status (go-gitea#34493) Rework delete org and rename org UI (go-gitea#34762) Refactor editor (go-gitea#34780) Improve img lazy loading (go-gitea#34804) [skip ci] Updated translations via Crowdin Fix Feishu webhook signature verification (go-gitea#34788) Upgrade chi to v5.2.2 (go-gitea#34798) Fix the issue of abnormal interface when there is no issue-item on the project page (go-gitea#34791) Fix container range bug (go-gitea#34795) Fix OCI manifest parser (go-gitea#34797) ...
Fix Feishu Webhook Signature Verification
This PR implements proper signature verification for Feishu (Lark) webhooks according to the official documentation.
Changes
GenSign
function based on Feishu's official Go sample codeImplementation Details
The signature verification works as follows:
timestamp + "\n" + secret
According to Feishu's documentation, the timestamp must be within 1 hour (3600 seconds) of the current time to be considered valid.
Security Note
Feishu emphasizes the importance of keeping webhook URLs secure. Do not disclose them on GitHub, blogs, or any public sites to prevent unauthorized use.
References