-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Validate app.bundlerOptions keys are objects in Bun.serve
#30518
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
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.
🔴 This fix is incomplete — the nested
minifyoption just below has the exact same bug.Bun.serve({ app: { bundlerOptions: { client: { minify: false } } } })(orminify: 128n) still falls through tominify_options.getBooleanLoose(...)on a non-object and trips the samedebugAssert(target.isObject())this PR is fixing. The boolean guard should handlefalse(and non-objects should throw) before callinggetBooleanLoose.Extended reasoning...
What the bug is
This PR adds an
isObject()guard at the top ofBuildConfigSubset.fromJS(src/bake/bake.zig:209-211) to preventdebugAssert(target.isObject())from firing when a non-object is passed forbundlerOptions.{server,client,ssr}. However, immediately below in the same function, the nestedminifysub-option is read viagetOptional(global, "minify", JSValue)and — if it isn't the booleantrue— passed straight togetBooleanLoose, which has the exact same precondition.Code path
In
BuildConfigSubset.fromJS:getBooleanLoose(src/jsc/JSValue.zig:1866-1868) callsthis.get(global, property_name), andget()begins withbun.debugAssert(target.isObject())(src/jsc/JSValue.zig:1534). So callinggetBooleanLooseon a non-object primitive trips the same assertion this PR was opened to fix.Why the existing guard doesn't help
The new
isObject()check at line 209 validatesjs_options(theclient/server/ssrobject), butminify_optionsis fetched from inside it viagetOptional(..., JSValue), which returns any non-null/undefined value untyped. The only guard onminify_optionsisisBoolean() and asBoolean(), which only short-circuits fortrue.Step-by-step proof
With
Bun.serve({ app: { bundlerOptions: { client: { minify: false } } } }):js_options={ minify: false }→ passes the newisObject()check at line 209.getOptional(global, "minify", JSValue)returns the JS booleanfalse.minify_options.isBoolean()=true,minify_options.asBoolean()=false→true and false=false. Does notbreak :brk.minify_options.getBooleanLoose(global, "whitespace").getBooleanLoosecallsthis.get(...)→bun.debugAssert(false.isObject())→ panic in debug builds.The same happens with
minify: 128n/5/"str"/Symbol()(step 3:isBoolean()isfalse, so the AND isfalse, fall through). Theminify: falsecase is particularly notable because it's a perfectly reasonable thing for a user to write.Impact
Same fingerprint class (
debugAssert target.isObject()inJSValue.get) as the crash this PR is fixing, in the very function this PR modified. The fuzzer will hit it next.Fix
Either change the boolean guard to handle both values (
if (minify_options.isBoolean()) { const b = minify_options.asBoolean(); options.minify_* = b; break :brk; }), or add anif (!minify_options.isObject()) return global.throwInvalidArguments(...)after the boolean check, mirroring what was done forjs_options. The new tests should also cover{ [key]: { minify: value } }for the same primitive set.