Skip to content

Fix Feishu webhook signature verification (#34788) #34802

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

Draft
wants to merge 1 commit into
base: release/v1.24
Choose a base branch
from

Conversation

GiteaBot
Copy link
Collaborator

Backport #34788 by @SnowballXueQiu

Fix Feishu Webhook Signature Verification

This PR implements proper signature verification for Feishu (Lark) webhooks according to the official documentation.

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

# 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]>
@GiteaBot GiteaBot added modifies/go Pull requests that update Go code type/bug labels Jun 20, 2025
@GiteaBot GiteaBot requested review from hiifong and wxiaoguang June 20, 2025 20:09
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 20, 2025
@GiteaBot GiteaBot added this to the 1.24.3 milestone Jun 20, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 20, 2025
@wxiaoguang wxiaoguang marked this pull request as draft June 21, 2025 03:42
@wxiaoguang
Copy link
Contributor

#34788 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/go Pull requests that update Go code type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants