Skip to content

Reject invalid Base64 characters in b64.b64decode() #263

Open
viccie30 wants to merge 2 commits intocertbot:mainfrom
viccie30:reject_unsafe_b64
Open

Reject invalid Base64 characters in b64.b64decode() #263
viccie30 wants to merge 2 commits intocertbot:mainfrom
viccie30:reject_unsafe_b64

Conversation

@viccie30
Copy link
Copy Markdown

Python's base64.urlsafe_b64decode() has 2 footguns. It silently ignores invalid Base64 characters. It also accepts and decodes the non-urlsafe counterparts of '-' and '_'.

According to RFC7515 the Base64 encoding must have "all trailing '=' characters omitted and [no] inclusion of any line breaks, whitespace, or other additional characters."

The test code wasn't run, because it was missing the base class declaration of the test classes. Once I added that and ran the tests, it specifically tests that trailing '=' characters are allowed, in contradiction to the RFC.

The check I added does allow trailing '=' characters, but I don't know if this is wanted.

Python's base64.urlsafe_b64decode() has 2 footguns. It silently ignores invalid Base64 characters. It also accepts and decodes the non-urlsafe counterparts of '-' and '_'.
@viccie30 viccie30 requested a review from a team as a code owner March 27, 2026 23:23
@viccie30 viccie30 requested a review from ohemorange March 27, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant