Repository navigation
fix(utils): encode and decode base64 without Buffer - #282
Merged
Merged
Conversation
Closes #276. `encodeToBase64` and `decodeFromBase64` used `Buffer`, which does not exist in a browser. `utils/index.ts` re-exports both from the package root, so every consumer that imports `@sasjs/utils` carried the reference into its browser bundle. While those bundles shipped a Node polyfill tree the reference was silently shimmed; now that consumers are dropping that tree - the adapter's browser bundle no longer carries one - it is a ReferenceError waiting for the first caller. Both functions now use the platform globals: - `TextEncoder` / `TextDecoder` carry the UTF-8 step. `btoa` is latin1, so encoding a password through it directly corrupts anything non-ASCII, and these values are stored. - The binary string is built in chunks rather than spreading a whole byte array into `String.fromCharCode`, which overflows the call stack on long input. - Whitespace is stripped before `atob`, because Buffer ignores it when decoding and `atob` does not - a wrapped or padded stored value still decodes. The stored format is unchanged: the `{sasjs_encoded}` prefix, 200 hex characters of obfuscation padding, and the fixed 200-character offset that `decodeFromBase64` strips. Credentials written by earlier releases keep decoding. Tests, because the failure mode is invisible in Node: - a non-ASCII password round-trips, which is what a naive swap to `btoa` would break - a round trip with the Buffer global deleted, which is the browser case - the module code contains no `Buffer` reference, comments aside Proven by reintroducing the Buffer implementation: two of them fail with `ReferenceError: Buffer is not defined`, and pass with the platform APIs. Full suite: 40 suites, 448 tests passing. tsc and prettier clean.
Contributor
Author
There was a problem hiding this comment.
Reviewed the full diff at e8e93df (base64 encode/decode moved off Buffer to TextEncoder/btoa/atob). The UTF-8 step is preserved on both sides, so the output stays byte-identical to the old Buffer path and previously stored values still decode; the chunked String.fromCharCode avoids the call-stack overflow on long input.
No blocking issues.
sasjs-gha Bot
pushed a commit
that referenced
this pull request
Oct 15, 2026
## [3.7.4](v3.7.3...v3.7.4) (2026-10-15) ### Bug Fixes * **utils:** encode and decode base64 without Buffer ([#282](#282)) ([79ef9c8](79ef9c8))
|
🎉 This PR is included in version 3.7.4 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #276.
encodeToBase64anddecodeFromBase64usedBuffer, which does not exist in a browser.utils/index.tsre-exports both from the package root, so every consumer importing@sasjs/utilscarried the reference into its browser bundle. While those bundles shipped a Node polyfill tree the reference was silently shimmed; now that consumers are dropping that tree - the adapter's browser bundle no longer carries one - it is aReferenceErrorwaiting for the first caller.Changes
TextEncoder/TextDecodercarry the UTF-8 step.btoais latin1, so encoding a password through it directly corrupts anything non-ASCII, and these values are stored.String.fromCharCode, which overflows the call stack on long input.atob: Buffer ignores it when decoding andatobdoes not, so a wrapped or padded stored value still decodes.The stored format is unchanged - the
{sasjs_encoded}prefix, 200 hex characters of padding, and the fixed 200-character offsetdecodeFromBase64strips - so credentials written by earlier releases keep decoding.Tests
The failure mode is invisible in Node, so:
btoawould breakBufferreference, comments asideProven by reintroducing the Buffer implementation:
Full suite: 40 suites, 448 tests passing. tsc and prettier clean.
Why now
This is the last unguarded host global in a browser-facing module of this package - the same class as the
process.platformreads fixed in #281. With both gone, a browser consumer of@sasjs/utilsneeds no polyfill for anything this package does itself.