fix(sandbox): don't crash disposing a QuickJS context with a pending bridge call - #10380
Open
kwburns-kong wants to merge 2 commits into
Open
fix(sandbox): don't crash disposing a QuickJS context with a pending bridge call#10380kwburns-kong wants to merge 2 commits into
kwburns-kong wants to merge 2 commits into
Conversation
… a dispose-vs-pending-bridge-call defect Audits the sandbox's async/reentrancy surface: disposing a QuickJS context while a __hostBridge call is still pending trips a fatal engine assertion in JS_FreeRuntime instead of a clean timeout error. Also pins three ruled-out hypotheses from the same pass (concurrent-render job-queue isolation, guest-internal unhandled-rejection safety, and marshal-boundary purity) so future reviews don't re-derive them. Full write-up recorded in the local (gist-backed, non-committed) SANDBOX-SECURITY-FINDINGS.md tracker.
…out QuickJS context runTagInSandbox disposed its QuickJSContext unconditionally, including when the sandbox's own timeout fired while a __hostBridge call was still outstanding. That left a live promise/continuation referenced inside the runtime, and freeing it (ctx.dispose()) tripped a fatal QuickJS engine assertion (JS_FreeRuntime's list_empty(&rt->gc_obj_list) check) instead of the intended clean timeout error. Track in-flight bridge calls per render and force them to a settled state (rejecting outstanding ones, draining the resulting jobs) before disposing, so the runtime's GC list is empty by the time it's freed. Also guard the bridge settle continuation itself so a call that resolves after the context is already gone, or whose return value isn't JSON-serializable, surfaces as an ordinary catchable error instead of a process-level unhandled rejection.
✅ Circular References ReportGenerated at: 2026-08-11T20:20:17.853Z Summary
Click to view all circular references in PR (9)Click to view all circular references in base branch (9)Analysis✅ No Change: This PR does not introduce or remove any circular references. This report was generated automatically by comparing against the |
jackkav
approved these changes
Aug 12, 2026
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.
What this PR does
This PR adds two sandbox fixes:
runTagInSandboxunconditionally disposed its QuickJS context, including when the sandbox's own timeout fired while a__hostBridgecall (any granted async capability i.enetwork,fs-read,storage, etc.) was still outstanding. That left a live promise/continuation referenced inside the runtime, and freeing it tripped a fatal QuickJS engine assertion (JS_FreeRuntime's list_empty(&rt->gc_obj_list) check) instead of the intended "Template tag sandbox timed out" error. Reachable by any plugin capability that's simply slow.Fix
pendingBridgeCalls).context, on timeout and as a finally-block backstop.contextis already gone, or a non-serializable return value, surfaces as a normal tag error instead of an unhandled rejection.No change to the error message callers see on timeout.
Test plan
packages/insomnia/src/templating/sandbox/async-boundary.regression.test.tsrewritten to assert the fixed behavior.