Skip to content

fix(wecom): pad aeskey before base64 decode to handle unpadded WeCom keys - #17858

Closed
elephantjohn wants to merge 1 commit into
NousResearch:mainfrom
elephantjohn:fix-wecom-aes-padding
Closed

fix(wecom): pad aeskey before base64 decode to handle unpadded WeCom keys#17858
elephantjohn wants to merge 1 commit into
NousResearch:mainfrom
elephantjohn:fix-wecom-aes-padding

Conversation

@elephantjohn

@elephantjohn elephantjohn commented Apr 30, 2026

Copy link
Copy Markdown

WeCom delivers aeskey as 43-char base64 strings without trailing '='
padding. Calling base64.b64decode() on it directly raises
binascii.Error: 'Incorrect padding', causing image/file decryption
to fail silently — users see no response when sending images.

Fix: append '=' chars to make the length a multiple of 4 before
decoding, which is the standard workaround for unpadded base64.

What does this PR do?

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

How to Test

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

  WeCom delivers aeskey as 43-char base64 strings without trailing '='
  padding. Calling base64.b64decode() on it directly raises
  binascii.Error: 'Incorrect padding', causing image/file decryption
  to fail silently — users see no response when sending images.

  Fix: append '=' chars to make the length a multiple of 4 before
  decoding, which is the standard workaround for unpadded base64.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/wecom WeCom / WeChat Work adapter duplicate This issue or pull request already exists labels Apr 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #14580 — same root cause (WeCom 43-char unpadded base64 aeskey). See also #14888, #11899.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #14580 — same root cause (WeCom 43-char unpadded base64 aeskey). See also #14888, #11899.

@teknium1

Copy link
Copy Markdown
Contributor

This appears to be implemented on current main by the same WeCom AES-key padding fix.

Evidence from automated hermes-sweeper review:

  • gateway/platforms/wecom.py:1046 pads aes_key to a multiple of four before base64.b64decode(...), which is the exact behavior requested here.
  • The fix was added by 8f4c0bf0882c3c7258a65e3adade12d5b08068ea (fix(wecom): pad base64 AES key before decode).
  • git tag --contains 8f4c0bf08 shows the fix is included in v2026.5.7 and later tags.
  • The duplicate discussion from @alt-glitch points to the same root cause: WeCom 43-character unpadded base64 aeskey values.

Closing this PR as already implemented on main. Thanks for reporting and sending the focused fix.

@teknium1 teknium1 closed this Jun 10, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/wecom WeCom / WeChat Work adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants