Possible regression in native crypto paths in componentize-js 0.20.0 due to preview1 random_get stubbing
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript, rust, wasm
Hướng nghiên cứu
Bắt đầu với stub_preview1 trong crates/spidermonkey-embedding-splicer/src/stub_wasi.rs và xem lại bản cập nhật StarlingMonkey trong commit 499a888. Tái hiện trường hợp RSA importKey, sau đó so sánh hành vi khi có và không có stubbing preview1 random_get. Hoàn thành khi đường dẫn mật mã native kết thúc mà không gặp trap random_get và hành vi dự kiến đã được xác minh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi all,
@maxim-le and I hit a runtime trap in componentize-js 0.20.0 and wanted to share what we found in case we are understanding the behavior correctly. We may be missing context, so I’m filing this as a question / possible bug rather than assuming the current implementation is wrong.
Symptom
We see traps like:
wasm trap: wasm unreachable instruction executed
0: ... !random_get
This happens for WebCrypto operations that appear to go through native crypto code, for example RSA private-key crypto.subtle.importKey("pkcs8", ...).
A simplified repro for us is:
async function main() {
const pem = `-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----`;
const pemBody = pem
.replace(/-----BEGIN PRIVATE KEY-----/, "")
.replace(/-----END PRIVATE KEY-----/, "")
.replace(/[\r\n\s]/g, "");
const keyBytes = Uint8Array.from(atob(pemBody), c => c.charCodeAt(0));
const key = await crypto.subtle.importKey(
"pkcs8",
keyBytes.buffer,
{ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
false,
["sign"]
);
return { imported: true, type: key.type };
}
What we found
The relevant code seems to be in:
crates/spidermonkey-embedding-splicer/src/stub_wasi.rs
fn stub_preview1(module: &mut Module) -> Result<()> {
// random comes from prevew2 only in StarlingMonkey
stub_import(module, PREVIEW1, "random_get", unreachable_stub)?;
Ok(())
}
The stub predates 0.20.0 by a long time. The main notable change between 0.19.3 (The previous version we used) and 0.20.0 relevant to this area appears to be the StarlingMonkey update in 499a888 ("Update StarlingMonkey (#325)"), which is consistent with the issue only becoming observable for us in 0.20.0.
Current hypothesis
Our current guess is:
- componentize-js 0.20.0 bumped StarlingMonkey in a way that now exercises a native crypto / libc entropy path that actually reaches preview1
random_get - once that path is exercised, the existing stub becomes visible as a trap
What we verified locally
We tested a local patch that stops stubbing random_get, rebuilt the splicer artifacts, and reran the same RSA importKey case.
With that patch in place, the trap disappeared and the operation completed successfully.
Because of that, it seems plausible that preview1 random_get still needs to remain available for some native crypto paths, even if most JS-visible randomness is coming from preview2.
Question
Does this sound like a real bug from your perspective, or is there intended behavior here that we are overlooking?
If useful, I’m happy to open a follow-up PR :)
Thanks.
- Ngôn ngữ chính
- Rust
- Star
- 392
- Fork
- 54
- Merge trung bình
- 3 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
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/ComponentizeJS
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 56/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
bytecodealliance/ComponentizeJS#335 · 3 bình luận ·
Tất cả issue của bytecodealliance/ComponentizeJS
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
gitbutlerapp/gitbutler#15998 · 1 bình luận ·
-
bug triage:deciding
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
open-telemetry/otel-arrow#4132 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100