fix(js-x-ray): decode base64 in Buffer.from require specifiers - #709
Merged
fraxken merged 1 commit intoSep 17, 2026
Merged
Conversation
`#handleBufferFrom` only reads an ArrayExpression argument. The hex form is
picked up earlier by the generic hex check on the first argument, and atob
has its own handler, so base64 through Buffer.from was the one spelling with
nothing behind it.
```js
require(Buffer.from("68747470", "hex").toString()) // http
require(atob("aHR0cA==")) // http
require(Buffer.from("aHR0cA==", "base64").toString()) // nothing
```
Gated on the existing isStringBase64 so a string that is not base64 does not
get decoded into noise. The unsafe-import warning stays either way, as it
does for the hex form.
馃 Changeset detectedLatest commit: 3ee8e79 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
fraxken
approved these changes
Sep 17, 2026
clemgbld
approved these changes
Sep 17, 2026
Merged
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.
#handleBufferFromonly reads anArrayExpressionargument. The hex form never reaches it, since it is picked up earlier by the generic hex check on the first argument of any call, andatobhas its own handler. That leaves base64 throughBuffer.fromas the one spelling with nothing behind it.Buffer.fromis the Node idiom here;atobis the browser one, so the gap is on the spelling more likely to show up in a package.Buffer.from([104, 116, 116, 112])"http", already workedBuffer.from("68747470", "hex")"http", already workedBuffer.from("aHR0cA==", "base64")"http"Buffer.from("not base64 at all!", "base64")nullThe last row is why it goes through the existing
isStringBase64rather than handing anything toBuffer.from: Node's base64 decoder is lenient and would happily turn arbitrary text into bytes, which would put junk in the dependency list.Only
base64is added, notbase64url, becauseisStringBase64matches the+/alphabet and would reject valid base64url. Happy to add it with its own check if you want it.unsafe-importstill fires, same as it does for the hex form, since the require is still dynamic. Two tests, one per new row.