Repository navigation
feat(channels): add the WeCom self-built app channel - #788
Merged
Merged
Conversation
WeCom (企业微信) delivers to a callback URL and encrypts the body, so this is the first provider whose inbound side is not just a parse. Both halves are security-relevant and both are checked: * the callback's `msg_signature` — SHA-1 over the token, timestamp, nonce and ciphertext, sorted and concatenated — is verified **before** anything is decrypted, because a ciphertext from the network is attacker-chosen input; * the decrypted envelope ends with the corp it was meant for, and that must be *this* corp, so a callback captured from another tenant cannot be replayed here. `transport/cipher.rs` is the AES-256-CBC + PKCS#7 piece. The platform hands the operator a 43-character base64 key that decodes to exactly 32 bytes; the first 16 double as the IV. The chaining is built on the `aes` block cipher rather than pulling in a mode crate, and both directions are pinned against the RFC 3602 AES-256-CBC vectors, with a round trip over lengths either side of a block boundary. `AesKey`'s `Debug` is hand-written and prints nothing: a derived one would put the key in any log that formats it. Outbound is `message/send` with the access token cached until shortly before it expires — fetching per message would hit the platform's own rate limit — and a rejected token is dropped from the cache so a retry does not reuse the dead one. The answer to a callback is an empty body (the documented "no passive reply"), which is what stops the platform retrying while the turn runs; the reply itself goes out through the send API. Two platform properties are handled rather than assumed. WeCom answers **HTTP 200 for failures**, with the real status in `errcode`, so every call checks the body and the error carries the code and its class — the class via `ErrorClass::label`, which the durable queue reads back. And a self-built app receives members' direct messages only, so every conversation is direct, the DM policy is the gate, and the mention gate stays off. An image or voice callback is dropped rather than becoming an empty prompt, since this provider resolves no attachments. `max_text_len` is 2048 **bytes**: one CJK character costs three, so the definition says bytes and the shared splitter is told the unit. The provider contract's requirements are met in full: the definition points at `docs/guide/channels-providers.md#wecom`, the matrix row and per-channel section are in both languages, and both new files measure **zero uncovered lines**. ## Documentation tidy-up The docs still carried the shape of a two-channel product, from when Feishu and DingTalk were the whole set. Fixed where it was actually wrong: * `directory-layout.md` (+ zh): the tree called `config.json` the "Feishu / DingTalk bridge config", and the section described the bridge as the Feishu and DingTalk one holding three blocks. It is every channel's config, with one `providers.<id>` block each. * the wiki sidebars (+ zh): "Integrations" listed only Feishu and DingTalk, which now reads as the complete set. They stay (they are the two setup guides) with a line pointing at the full channel list. * `channels-config.md` (+ zh): the introduction enumerated all twelve framework channels by name — a list that has to be edited every time one is added, and that the linked page already carries authoritatively. It now points at it. This is the drift the tidy is for, so it is removed rather than extended. ## Tooling `scripts/check-channel-matrix.py` iterated the *table* and skipped a provider it had no row for, so a channel added without a row passed silently — which is exactly what adding this one did. It now also checks the other direction: every provider in the framework registry must appear in the table. Verified as a real guard by deleting the new row and watching it fail with `MISSING wecom: registered but has no row in the matrix`. The docs-target invariant caught two mistakes while this was written, which is worth recording: a heading of `### WeCom (企业微信)` slugs to `wecom-企业微信` (those characters are alphanumeric), so the anchor is now the plain `### WeCom` like every other heading on the page. `docs/architecture/channels-test-coverage.md` (+ zh) now records that the out-of-scope count is 25 **or 26**: `feishu/feishu_ws.rs:254` sits inside a race its own test deliberately tolerates, so a measurement of 47 and one of 48 can both be right and a single extra line there is not evidence a change added it.
huichen
enabled auto-merge (squash)
September 23, 2026 01:36
CI caught a real defect in this test, not a flake:
providers::wecom::tests::a_callback_encrypted_with_another_key_is_rejected
the envelope declares 1868454428 bytes of message but only 315 follow the prefix
The test fed a message from the `text_message` fixture, which stamps itself with
the current time so that the bridge does not discard it as a stale replay. That
made the ciphertext change every second, and the test then depended on which
check catches a wrong key: the padding check, or — when the final byte happens to
look like valid padding — the envelope's own length check. Locally it landed on
the padding branch; CI ran in a different second and landed on the other one.
The bytes are now pinned with `message_with`, and the assertion accepts the two
honest outcomes ("padding" or "declares") instead of only the one that happened
to occur here. `encrypted_with` is factored out so a ciphertext under an
arbitrary key reads the same as the other fixtures.
Verified by running the test 20 times: all green, where before it passed or
failed depending on the second it ran in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(channels): add the WeCom self-built app channel
WeCom (企业微信) delivers to a callback URL and encrypts the body, so this is
the first provider whose inbound side is not just a parse. Both halves are
security-relevant and both are checked:
msg_signature— SHA-1 over the token, timestamp, nonce andciphertext, sorted and concatenated — is verified before anything is
decrypted, because a ciphertext from the network is attacker-chosen input;
this corp, so a callback captured from another tenant cannot be replayed
here.
transport/cipher.rsis the AES-256-CBC + PKCS#7 piece. The platform hands theoperator a 43-character base64 key that decodes to exactly 32 bytes; the first
16 double as the IV. The chaining is built on the
aesblock cipher rather thanpulling in a mode crate, and both directions are pinned against the RFC 3602
AES-256-CBC vectors, with a round trip over lengths either side of a block
boundary.
AesKey'sDebugis hand-written and prints nothing: a derived onewould put the key in any log that formats it.
Outbound is
message/sendwith the access token cached until shortly before itexpires — fetching per message would hit the platform's own rate limit — and a
rejected token is dropped from the cache so a retry does not reuse the dead one.
The answer to a callback is an empty body (the documented "no passive reply"),
which is what stops the platform retrying while the turn runs; the reply itself
goes out through the send API.
Two platform properties are handled rather than assumed. WeCom answers HTTP
200 for failures, with the real status in
errcode, so every call checks thebody and the error carries the code and its class — the class via
ErrorClass::label, which the durable queue reads back. And a self-built appreceives members' direct messages only, so every conversation is direct, the DM
policy is the gate, and the mention gate stays off. An image or voice callback is
dropped rather than becoming an empty prompt, since this provider resolves no
attachments.
max_text_lenis 2048 bytes: one CJK character costs three, so the definitionsays bytes and the shared splitter is told the unit.
The provider contract's requirements are met in full: the definition points at
docs/guide/channels-providers.md#wecom, the matrix row and per-channel sectionare in both languages, and both new files measure zero uncovered lines.
Documentation tidy-up
The docs still carried the shape of a two-channel product, from when Feishu and
DingTalk were the whole set. Fixed where it was actually wrong:
directory-layout.md(+ zh): the tree calledconfig.jsonthe "Feishu /DingTalk bridge config", and the section described the bridge as the Feishu and
DingTalk one holding three blocks. It is every channel's config, with one
providers.<id>block each.now reads as the complete set. They stay (they are the two setup guides) with a
line pointing at the full channel list.
channels-config.md(+ zh): the introduction enumerated all twelve frameworkchannels by name — a list that has to be edited every time one is added, and
that the linked page already carries authoritatively. It now points at it.
This is the drift the tidy is for, so it is removed rather than extended.
Tooling
scripts/check-channel-matrix.pyiterated the table and skipped a provider ithad no row for, so a channel added without a row passed silently — which is
exactly what adding this one did. It now also checks the other direction: every
provider in the framework registry must appear in the table. Verified as a real
guard by deleting the new row and watching it fail with
MISSING wecom: registered but has no row in the matrix.The docs-target invariant caught two mistakes while this was written, which is
worth recording: a heading of
### WeCom (企业微信)slugs towecom-企业微信(those characters are alphanumeric), so the anchor is now the plain
### WeComlike every other heading on the page.
docs/architecture/channels-test-coverage.md(+ zh) now records that theout-of-scope count is 25 or 26:
feishu/feishu_ws.rs:254sits inside a raceits own test deliberately tolerates, so a measurement of 47 and one of 48 can
both be right and a single extra line there is not evidence a change added it.