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(basic-auth): handle passing invalid value to atob() #1122

Merged
merged 2 commits into from May 21, 2023

Conversation

yusukebe
Copy link
Member

@yusukebe yusukebe commented May 21, 2023

This PR will fix #1121.

If an invalid value like G9ubzphY29vbHByb2plY3Q= is passed to atob(), it should throw a DOMException. However, the existing Basic Auth middleware cannot handle this, resulting in a "500 Internal Error" when an invalid string is sent.

The jest-environment-miniflare testing environment does not throw an exception from atob(). Therefore, this PR includes a test for this in runtime_tests/deno/middleware.test.tsx. The implementation in Deno is correct according to the spec.

Regarding the implementation, it uses try, even though we can check if the string is valid or invalid for Base64. This is because testing is difficult due to the above reasons, so I believe we need to keep the implementation as simple as possible.

@yusukebe yusukebe merged commit 2cfafe9 into main May 21, 2023
8 checks passed
@yusukebe yusukebe deleted the fix/invalid-base64 branch May 21, 2023 11:48
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.

Unexpected 500 Error, Instead of 401 in Basic Auth Middleware.
1 participant