You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add the ignorechars parameter in the Base64 decoder #144001
Earlier standards for Base64 (RFC 1421, RFC 1521) on which the base64 and binascii modules are based, specified that any non-alphabet characters should be ignored, and this is the default behavior of these modules. More modern standard (RFC 4648) considers this a vulnerability, and specify that they should be rejected until the upper lever document states otherwise. Thus, strict_mode/validate parameters were added. But they are "all-or-nothing" -- either all non-alphabet characters are rejected, or other errors are ignored. In some cases we need to ignore only the part of errors -- for example, ignore newlines and whitespaces, but not other invalid characters, or ignore padding errors.
a85decode() has parameter ignorechars which could also be used to control Base64 decoding.
This PR adds ignorechars parameter to binascii.a2b_base64() and base64.b64decode() with O(1) lookup table, tests, and NEWS entry.
If this aligns with you have in your mind, feel free to merge or let me know what to cherry-pick from it. Otherwise If you'd prefer a different approach or it needs significant changes, please let me know or feel free to create your own implementation, if not I am happy to close mine in that case.
PR #144306 extend the function of ignorechars and allows to support the following optional features (RFC 4648, section 3.3):
Furthermore, such specifications MAY ignore the pad
character, "=", treating it as non-alphabet data, if it is present
before the end of the encoded data. If more than the allowed number
of pad characters is found at the end of the string (e.g., a base 64
string terminated with "==="), the excess pad characters MAY also be
ignored.
Now, if ignorechars contains the pad character '=', the pad characters presented before the end of the encoded data and the excess pad characters will be ignored.
And since ignorechars is a new parameter, no need to restore the deprecated behavior and emit corresponding warnings when both altchars and ignorechars are specified. #144324 makes it matching the future more secure behavior. It also makes the code simpler.
Activity
pythongh-144001: Add ignorechars parameter to Base64 decoder
moneebullah25 commentedon Jan 18, 2026
Hi @serhiy-storchaka
I've implemented this feature in PR #144009.
This PR adds ignorechars parameter to binascii.a2b_base64() and base64.b64decode() with O(1) lookup table, tests, and NEWS entry.
If this aligns with you have in your mind, feel free to merge or let me know what to cherry-pick from it. Otherwise If you'd prefer a different approach or it needs significant changes, please let me know or feel free to create your own implementation, if not I am happy to close mine in that case.
pythongh-144001: Register ignorechars identifier in global strings
pythongh-144001: removed news entry and blurbed it
pythongh-144001: Support ignorechars in binascii.a2b_base64() and bas…
serhiy-storchaka commentedon Jan 19, 2026
Sorry, @moneebullah25, but I already had my code before opening this issue. I only needed to solve a pair of corner cases.
pythongh-144001: Support ignorechars in binascii.a2b_base64() and bas…
pythongh-144001: Support ignorechars in binascii.a2b_base64() and bas…
gh-144001: Support ignorechars in binascii.a2b_base64() and base64.b6…
gpshead commentedon Jan 26, 2026
a followup PR is likely needed per #144024 (comment)
pythongh-144001: Support ignoring the invalid pad character in Base64…
pythongh-144001: Support ignoring the invalid pad character in Base64…
serhiy-storchaka commentedon Jan 28, 2026
PR #144306 extend the function of
ignorecharsand allows to support the following optional features (RFC 4648, section 3.3):Now, if
ignorecharscontains the pad character'=', the pad characters presented before the end of the encoded data and the excess pad characters will be ignored.pythongh-144001: Simplify Base64 decoding with altchars and ignorecha…
serhiy-storchaka commentedon Jan 29, 2026
And since ignorechars is a new parameter, no need to restore the deprecated behavior and emit corresponding warnings when both
altcharsandignorecharsare specified. #144324 makes it matching the future more secure behavior. It also makes the code simpler.gh-144001: Simplify Base64 decoding with altchars and ignorechars spe…
pythongh-144001: Simplify Base64 decoding with altchars and ignorecha…
gh-144001: Support ignoring the invalid pad character in Base64 decod…
pythongh-144001: Support ignorechars in binascii.a2b_base64() and bas…
pythongh-144001: Simplify Base64 decoding with altchars and ignorecha…
pythongh-144001: Support ignoring the invalid pad character in Base64…
pythongh-144001: Support ignoring the invalid pad character in Base64…