Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(encoding/base64url): throw TypeError in case of invalid base64url string #1040

Merged
merged 4 commits into from
Jul 26, 2021

Conversation

TotallyNotChase
Copy link
Contributor

fixes #1011

Validate input in base64url decoder.

Add tests for making sure invalid base64url strings are rejected.

@@ -17,6 +17,10 @@ export function addPaddingToBase64url(base64url: string): string {
}

function convertBase64urlToBase64(b64url: string): string {
if (!/^[-_A-Z0-9]*?={0,2}$/i.test(b64url)) {
// Contains characters not part of base64url spec.
throw new TypeError("Invalid base64url character in string!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should align the error message with base64.decode like:

throw new TypeError("Failed to decode base64url: invalid character);

BTW @lucacasonato do you think the error here should be DOMException?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, for the time being. Awaiting input on whether or not this should be a DOMException.

@kt3k
Copy link
Member

kt3k commented Jul 19, 2021

The test case looks good to me

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju bartlomieju merged commit 68a671f into denoland:main Jul 26, 2021
@TotallyNotChase TotallyNotChase deleted the base64url_fix branch July 26, 2021 13:10
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.

base64url decoder allows decoding base64
3 participants