From 21780075e4e6efebf3cb410d5de05d9943e07637 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Wed, 9 Jul 2025 23:57:38 +0100 Subject: [PATCH] src: check import attributes value types as strings PR-URL: https://github.com/nodejs/node/pull/58986 Reviewed-By: Guy Bedford Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Marco Ippolito Reviewed-By: Ethan Arrowood --- src/module_wrap.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 3d27b878fd2..83728032406 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -63,6 +63,10 @@ using v8::UnboundModuleScript; using v8::Undefined; using v8::Value; +inline bool DataIsString(Local data) { + return data->IsValue() && data.As()->IsString(); +} + void ModuleCacheKey::MemoryInfo(MemoryTracker* tracker) const { tracker->TrackField("specifier", specifier); tracker->TrackField("import_attributes", import_attributes); @@ -83,6 +87,9 @@ ModuleCacheKey ModuleCacheKey::From(Local context, for (int i = 0; i < import_attributes->Length(); i += elements_per_attribute) { + DCHECK(DataIsString(import_attributes->Get(context, i))); + DCHECK(DataIsString(import_attributes->Get(context, i + 1))); + Local v8_key = import_attributes->Get(context, i).As(); Local v8_value = import_attributes->Get(context, i + 1).As(); @@ -488,9 +495,14 @@ static Local createImportAttributesContainer( LocalVector values(isolate, num_attributes); for (int i = 0; i < raw_attributes->Length(); i += elements_per_attribute) { + Local key = raw_attributes->Get(realm->context(), i); + Local value = raw_attributes->Get(realm->context(), i + 1); + DCHECK(DataIsString(key)); + DCHECK(DataIsString(value)); + int idx = i / elements_per_attribute; - names[idx] = raw_attributes->Get(realm->context(), i).As(); - values[idx] = raw_attributes->Get(realm->context(), i + 1).As(); + names[idx] = key.As(); + values[idx] = value.As(); } Local attributes = Object::New( @@ -507,6 +519,7 @@ static Local createModuleRequestsContainer( LocalVector requests(isolate, raw_requests->Length()); for (int i = 0; i < raw_requests->Length(); i++) { + DCHECK(raw_requests->Get(context, i)->IsModuleRequest()); Local module_request = raw_requests->Get(realm->context(), i).As();