fix(gmail): prevent URL corruption in quoted-printable decoding#186
Open
100menotu001 wants to merge 2 commits intosteipete:mainfrom
Open
fix(gmail): prevent URL corruption in quoted-printable decoding#186100menotu001 wants to merge 2 commits intosteipete:mainfrom
100menotu001 wants to merge 2 commits intosteipete:mainfrom
Conversation
added 2 commits
February 4, 2026 17:39
When Gmail API returns already-decoded content (format=full), the Content-Transfer-Encoding header may still say 'quoted-printable'. Previously, we would attempt to QP-decode again, causing raw '=' characters in URLs to be replaced with U+FFFD (replacement char). This adds looksLikeQuotedPrintable() to detect actual QP sequences (=XX hex or =CRLF soft breaks) and skip decoding when content appears pre-decoded. Fixes steipete#159
Matt's security review caught that URLs like '?foo=bar' would incorrectly trigger QP detection because '=ba' matches as hex digits. Changed to only match UPPERCASE hex (0-9, A-F) since: - RFC 2045 recommends uppercase for QP encoding - Most encoders use uppercase in practice - This avoids false positives from lowercase URL params
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.
Summary
Fixes #159 — URLs with
=characters were being corrupted to U+FFFD when emails hadContent-Transfer-Encoding: quoted-printablebut content was already decoded by Gmail API.Root Cause
Gmail API's
format=fullmay return body.data with content already decoded from its original transfer encoding, but the CTE header still indicatesquoted-printable. The existing code would attempt to QP-decode again, causing:=characters (from URLs like?foo=bar) treated as invalid QP sequencesquotedprintable.Readerproduces U+FFFD for invalid sequencesSolution
Added
looksLikeQuotedPrintable()check (similar to existinglooksLikeBase64()) that detects actual QP markers before decoding:=\r\nor=\n)=XXwhere X is 0-9 or A-F)Using uppercase-only hex detection avoids false positives from URLs containing lowercase letters after
=(e.g.,?foo=bar).Testing
Added unit tests covering:
Contributed via OpenClaw agent — active gog CLI users contributing back.