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

isBase64 padding support #2501

Open
antonio-ivanovski opened this issue Nov 21, 2024 · 3 comments · May be fixed by #2509
Open

isBase64 padding support #2501

antonio-ivanovski opened this issue Nov 21, 2024 · 3 comments · May be fixed by #2509
Labels

Comments

@antonio-ivanovski
Copy link

Describe the bug

Sometimes when base64 strings has the padding removed for either legacy or bandwidth purposes. In those cases, the padding check needs to be ignored or manually the padding to be added.

Either this should be the default behavior or config option should be added.

Examples

// const base64 = Buffer.from([1,2,3,4]).toString('base64');
const base64 = 'AQIDBA';
const result = isBase64(base64); // false, should be true
@jamro
Copy link

jamro commented Dec 8, 2024

I think this is expected behaviour. While RFC 4648 permits Base64 without padding, it states that padding should be used unless all parties involved agree to omit it.

Implementations MUST include appropriate pad characters at the end of
encoded data unless the specification referring to this document
explicitly states otherwise.

isBase64 has the flag urlSafe, which could be used to handle legacy use cases.

const result = validator.isBase64(base64, {urlSafe:  true}); // true

@antonio-ivanovski
Copy link
Author

isBase64 has the flag urlSafe, which could be used to handle legacy use cases.

The base64url is different encoding to the normal base64, other encoding dictionary is used.w

I think this is expected behaviour. While RFC 4648 permits Base64 without padding, it states that padding should be used unless all parties involved agree to omit it.

Makes sense for the current behaviour to be the default one, considering it is part of the spec. But it seems reasonable to me there to be an option to support such cases where the parties agree to such behaviour.

jamro added a commit to jamro/validator.js that referenced this issue Dec 13, 2024
@jamro jamro linked a pull request Dec 13, 2024 that will close this issue
4 tasks
@jamro
Copy link

jamro commented Dec 13, 2024

makes sense @antonio-ivanovski

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants