fix: replace abort-on-invalid-label with graceful bounds check#1416
Closed
santhsecurity wants to merge 1 commit intoquickjs-ng:masterfrom
Closed
fix: replace abort-on-invalid-label with graceful bounds check#1416santhsecurity wants to merge 1 commit intoquickjs-ng:masterfrom
santhsecurity wants to merge 1 commit intoquickjs-ng:masterfrom
Conversation
The update_label function uses assert() to validate the label index, which calls abort() on failure. In embedding contexts where QuickJS executes untrusted JavaScript (sandboxes, URL detonation engines, server-side JS), crafted scripts can trigger the assertion through pathological code patterns that produce invalid label indices during bytecode optimization. This turns a logic error into a process-killing SIGABRT — a denial-of-service vector for any application embedding QuickJS. The fix replaces the fatal assert with a bounds check that returns -1. Callers that check the return value (e.g., the if (update_label(...) > 0) pattern in resolve_labels) already handle -1 correctly. Callers that ignore the return value are unaffected — a -1 return on an invalid label is strictly better than a process abort. The second assert (ref_count >= 0) is similarly replaced with a clamp to zero, preventing underflow from cascading into further undefined behavior. Discovered during adversarial testing of the Sear URL detonation engine (https://santh.io/sear), which executes untrusted JavaScript from phishing pages in a QuickJS sandbox.
Contributor
|
I'm not sure about this one. The whole bytecode reader was not designed for untrusted input. You can patch some calls but I think there are way more that would surface with specially crafter payloads. Why not evaluate JS code rather than bytecode? |
Contributor
Assuming that's actually possible, then that's a bug and it needs to be fixed, not worked around. |
Contributor
|
I don't think we'll be merging this so I'm going to close it. Thanks anyway for the pull request. |
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.
The update_label function uses assert() to validate the label index, which calls abort() on failure. In embedding contexts where QuickJS executes untrusted JavaScript (sandboxes, URL detonation engines, server-side JS), crafted scripts can trigger the assertion through pathological code patterns that produce invalid label indices during bytecode optimization.
This turns a logic error into a process-killing SIGABRT, which is a denial-of-service vector for any application embedding QuickJS.
The fix replaces the fatal assert with a bounds check that returns -1. Callers that check the return value (e.g., the if (update_label(...) > 0) pattern in resolve_labels) already handle -1 correctly. Callers that ignore the return value are unaffected. An a -1 return on an invalid label is strictly better than a process abort.
The second assert (ref_count >= 0) is similarly replaced with a clamp to zero, preventing underflow from cascading into further undefined behavior.
Discovered during adversarial testing of the Sear URL detonation engine (https://santh.io/sear), which executes untrusted JavaScript from phishing pages in a QuickJS sandbox.