Module loader ignores import attributes: JSON modules fail, and `with { type: "json" }` executes a JavaScript file
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Start in runtime/script_loader.cpp at module_load_hook, then read how get_module compiles modules and how moduleRegistry keys them. Compare that flow with SpiderMonkey's GetModuleRequestType and CompileJsonModule APIs cited in the issue. Run the listed JSON import reproductions and test262 json-* tests; done means JSON imports export parsed values, invalid JSON and unknown types error, and imports with different attributes remain distinct.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
module_load_hook never looks at the import attributes of a request, so every module is compiled as JavaScript:
import data from "./data.json" with { type: "json" }fails (an object is parsed as a JS block; an array has no
defaultexport).- A file imported with
type: "json"that actually contains JavaScript is executed. - Unknown
typevalues are accepted silently.
Environment
- StarlingMonkey v0.4.0 release
starling.wasm, wasmtime 50.0.1, module mode (wasmtime run -S http --dir . starling.wasm main.js). runtime/script_loader.cppis unchanged onmain(54b3329b).- Checked on 2026-11-03. Reference: SpiderMonkey jsshell 147.0.4 (the SpiderMonkey version StarlingMonkey v0.4.0 embeds),
js -m.
Reproduction
data.json: {"a": 1, "n": -1.5e-3} · arr.json: [1,2] · evil.json: console.log("JS CODE EXECUTED"); export default 42;
// main.js
import obj from "./data.json" with { type: "json" };
console.log(JSON.stringify(obj));
| import | StarlingMonkey | jsshell 147.0.4 |
|---|---|---|
./data.json with type: "json" |
data.json:1:5 SyntaxError: unexpected token: ':' |
{"a":1,"n":-0.0015} |
./arr.json with type: "json" |
SyntaxError: The requested module 'arr.json' doesn't provide an export named: 'default' |
[1,2] |
./evil.json with type: "json" |
prints JS CODE EXECUTED, then imported 42 |
SyntaxError: JSON.parse: unexpected character at line 1 column 1 |
./b.js with type: "bogus" |
attribute ignored | TypeError: invalid module type |
test262: language/import/import-attributes/json-value-object.js, json-idempotency.js and the other json-* tests in
that directory fail.
Expected
ECMA-262 HostLoadImportedModule: "If moduleRequest.[[Attributes]]
has an entry entry such that entry.[[Key]] is "type" and entry.[[Value]] is "json", … result must either be the
Completion Record returned by an invocation of ParseJSONModule or a
throw completion." So a JSON import yields a module whose default export is the parsed value, and non-JSON content
is an error, never executed. ModuleRequestsEqual also compares
attributes, so ./x with and without type: "json" are different requests.
The point of type: "json" is that importing data cannot run code; currently that guarantee does not hold.
Cause
module_load_hook in runtime/script_loader.cpp resolves the specifier and always calls get_module(...), which
compiles the source as a JavaScript module. It never reads the request's module type, and moduleRegistry is keyed by
resolved path only.
Suggested fix (sketch)
In module_load_hook, read the module type from the request (JS::GetModuleRequestType(cx, moduleRequest) returns
JS::ModuleType::JSON for type: "json"). For JSON, compile with JS::CompileJsonModule(cx, opts, source), as
jsshell's ModuleLoader::loadAndParse does. Key the registry by (resolved path, module type), and reject unknown
types with a TypeError.
- Ngôn ngữ chính
- C
- Star
- 297
- Fork
- 64
- Merge trung bình
- 2 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 19
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bytecodealliance/StarlingMonkey
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
bytecodealliance/StarlingMonkey#359 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bytecodealliance/StarlingMonkey#355 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 68/100
bytecodealliance/StarlingMonkey#358 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
bytecodealliance/StarlingMonkey#357 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 44/100
bytecodealliance/StarlingMonkey#354 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bytecodealliance/StarlingMonkey
Issue tương tự
-
[yugabyted] xcluster set_up and add_to_replication fail for database names containing - . or (Đang mởkind/bug priority/medium qa_automation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
yugabyte/yugabyte-db#37324 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
meshcore-dev/MeshCore#3781 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
ly05010419/MacNativeGames#1897 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: metrics area: tracing contribfest enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
open-telemetry/opentelemetry-ebpf-instrumentation#4188 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày