gitea/services/webhook
Snowball_233 40dec17b5c
Fix Feishu webhook signature verification (#34788)
# 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 <i@hiif.ong>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-06-20 13:09:03 -07:00
..
deliver_test.go Enable addtional linters (#34085) 2025-04-01 10:14:01 +00:00
deliver.go Enable addtional linters (#34085) 2025-04-01 10:14:01 +00:00
dingtalk_test.go Use test context in tests and new loop system in benchmarks (#33648) 2025-02-20 09:57:40 +00:00
dingtalk.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
discord_test.go Use test context in tests and new loop system in benchmarks (#33648) 2025-02-20 09:57:40 +00:00
discord.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
feishu_test.go Fix Feishu webhook signature verification (#34788) 2025-06-20 13:09:03 -07:00
feishu.go Fix Feishu webhook signature verification (#34788) 2025-06-20 13:09:03 -07:00
general_test.go Add tests for webhook and fix some webhook bugs (#33396) 2025-01-30 03:09:48 +00:00
general.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
main_test.go make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
matrix_test.go Use test context in tests and new loop system in benchmarks (#33648) 2025-02-20 09:57:40 +00:00
matrix.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
msteams_test.go Enable testifylint rules (#34075) 2025-03-31 01:53:48 -04:00
msteams.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
notifier.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
packagist_test.go Enable testifylint rules (#34075) 2025-03-31 01:53:48 -04:00
packagist.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
payloader.go Fix Feishu webhook signature verification (#34788) 2025-06-20 13:09:03 -07:00
slack_test.go Use test context in tests and new loop system in benchmarks (#33648) 2025-02-20 09:57:40 +00:00
slack.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
telegram_test.go Use test context in tests and new loop system in benchmarks (#33648) 2025-02-20 09:57:40 +00:00
telegram.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00
webhook_test.go Refactor some tests (#34580) 2025-06-03 01:26:19 +00:00
webhook.go Add tests for webhook and fix some webhook bugs (#33396) 2025-01-30 03:09:48 +00:00
wechatwork.go Add workflow_run api + webhook (#33964) 2025-06-20 20:14:00 +08:00