-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(isBase64): improve base64 validation based on RFC4648 #2491
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
Conversation
add padding to the option list update regexes to support validation with/without padding update default options to keep the changes backward compatible add new test to cover different scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick updates. I'll need to take some more time for a proper review, but on initial look this should be good so I'll request some additional reviewers already
UP |
Just a heads up this caused a stack overflow issue in our app.
... Sorry, if I can create a reproducible scenario I will open an issue. |
The regular expression used here can cause a ReDoS on large strings. The old implementation was more efficient because the iteration was handled by JS, not by the RegEx. |
Feel free to open a new PR with an improved version |
I've created #2574 to resolve the stack overflow issue |
Add padding to the options list.
Update regexes to support validation with and without padding.
Update default options to maintain backward compatibility.
Add new tests to cover various scenarios.
In the previous version, only Base64 strings with padding and URL-safe Base64 strings without padding were validated. However, according to RFC4648, both standard and URL-safe Base64 variants can be valid with or without padding. Therefore, this version supports four validation combinations—standard with padding, standard without padding, URL-safe with padding, and URL-safe without padding—while maintaining backward compatibility.
Checklist