Merged
Conversation
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.
This fixes Weixin inbound PDF handling so uploaded documents are either stored as real files or explicitly rejected instead of being surfaced as unusable garbage data.
Before this change, the Weixin runtime only summarized inbound
file_itempayloads as text and did not persist them at all. After adding persistence, it became clear that the CDN download path could still save encrypted or malformed payloads as.pdffiles because the upstream metadata is inconsistent:encrypt_typemay be0even when anaes_keyis present, and the key itself may be encoded in more than one way. In practice that meant users could send a PDF, see a saved path, and still end up with a file whose contents were not actually a PDF.The fix adds an inbound file pipeline for Weixin that downloads
file_item.media, attempts decryption across the key encodings and AES key sizes observed in the payloads, validates the resulting bytes against the expected file signature, and only then writes into the working directory uploads tree. For PDFs specifically, the runtime now requires a valid%PDF-header and tolerates a short prefix before the header if Weixin prepends extra bytes. When validation fails, the runtime records a cleardownload_failed=...note instead of writing a bad file.The change also improves observability around this path. We now log whether media metadata exists, whether an AES key was present, the raw key length, candidate decoded key lengths, and the truncated media JSON on failure. That makes further protocol mismatches debuggable without having to inspect the database or saved files manually.
Validation used
cargo test weixin -- --nocapture, including new tests that cover successful inbound download-and-save behavior and rejection of invalid PDF payloads.