Skip to content

fix: prevent panic on dynamic import with non-string error name#32498

Merged
bartlomieju merged 2 commits intodenoland:mainfrom
kajukitli:fix-dynamic-import-panic
Mar 5, 2026
Merged

fix: prevent panic on dynamic import with non-string error name#32498
bartlomieju merged 2 commits intodenoland:mainfrom
kajukitli:fix-dynamic-import-panic

Conversation

@kajukitli
Copy link
Copy Markdown
Contributor

@kajukitli kajukitli commented Mar 5, 2026

Summary

Fixes a denial-of-service vulnerability where a dynamic import rejecting with an Error whose name property is a non-string type (Number, Object, Symbol) would panic and terminate the Deno process.

The Problem

In catch_dynamic_import_promise_error, the code deserializes the error:

let e: crate::error::NativeJsError = serde_v8::from_v8(scope, arg).unwrap();

When name is not a string, serde_v8::from_v8 returns an error and .unwrap() panics. This bypasses all JavaScript-level error handling.

The Fix

Replace .unwrap() with .unwrap_or_default():

let e: crate::error::NativeJsError =
    serde_v8::from_v8(scope, arg).unwrap_or_default();

NativeJsError already derives Default, so this gracefully handles malformed errors with name: None, message: None.

PoC (before fix)

try {
  await import(\`data:application/javascript,
    const e = new Error("x");
    Object.defineProperty(e, "name", { value: 42 });
    throw e;
  \`);
} catch (e) {
  console.log("never reached");
}

Result: panicked at libs/core/runtime/bindings.rs:961:72

When a dynamic import rejects with an Error whose 'name' property is a
non-string type (e.g., Number, Object, Symbol), serde_v8::from_v8 would
fail and the subsequent .unwrap() would panic, terminating the entire
Deno process.

This changes the .unwrap() to .unwrap_or_default(), allowing the error
to be handled gracefully with a default NativeJsError (which has
name: None, message: None).

Security: GHSA-2f8r-ppr9-ff8f
When processing errorAdditionalPropertyKeys, if a property getter throws,
the .unwrap() calls on arr.get_index() and exception.get() would panic.

Replace unwrap() with let-else patterns that skip problematic properties
instead of crashing.
@bartlomieju bartlomieju merged commit f1d7d0c into denoland:main Mar 5, 2026
112 checks passed
bartlomieju pushed a commit to bartlomieju/deno that referenced this pull request Mar 5, 2026
…land#32498)

Fixes a panic where a dynamic import rejecting
with an Error whose `name` property is a non-string type (Number,
Object, Symbol) would panic and terminate the Deno process.

---------

Co-authored-by: kaju <kajukitli@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants