Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

spawn drops an own `__proto__` environment entry

Đang mở Phù hợp với người mới
#993 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@nikolay-dementiev đang làm issue này rồi.

Từ ngày 15/10/2026.

  • #994 của @nikolay-dementiev — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
nodejs, typescript
Lĩnh vực
operating-systems

Hướng nghiên cứu

Bắt đầu từ hàm trợ giúp assign trong src/utils.ts, hàm này sao chép options.env vào đích bằng phép gán thuộc tính thông thường, nên một khóa __proto__ riêng sẽ chạm vào setter của prototype. Theo dõi cách spawn truyền env đó sang _parseEnv. Chạy lại bước tái hiện trong issue và kiểm tra xem tiến trình con có in ra true:selected-value hay không. Công việc hoàn thành khi một mục __proto__ vẫn còn sau khi sao chép, dùng defineProperty hoặc cách tương đương, và bước tái hiện chạy đạt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Environment details

  • OS: macOS (arm64)
  • OS version: 26.5.2
  • node-pty version: 1.1.0 (Node.js 26.3.0)

Issue description

spawn copies options.env with assign (src/utils.ts):

sources.forEach(source => Object.keys(source).forEach(key => target[key] = source[key]));

When the source object has an own __proto__ key (for example one that came from JSON.parse), target["__proto__"] = value invokes the Object.prototype.__proto__ setter instead of creating a property. A string value is ignored, so the variable never reaches _parseEnv and the child starts without it. child_process passes the same object through.

const pty = require("node-pty");
const env = { ...process.env, ...JSON.parse('{"__proto__":"selected-value"}') };
console.log(Object.hasOwn(env, "__proto__")); // true
const child = "console.log(Object.hasOwn(process.env, '__proto__') + ':' + process.env['__proto__'])";
pty.spawn(process.execPath, ["-e", child], { env }).onData((d) => process.stdout.write(d));
// prints: false:[object Object]

With child_process.execFileSync(process.execPath, ["-e", child], { env }) the child prints true:selected-value, and launching through /usr/bin/env __proto__=selected-value node -e ... under node-pty does too, so the operating system and Node accept the name.

Copying with Object.defineProperty(target, key, { value: source[key], enumerable: true, writable: true, configurable: true }), or building the key=value pairs from the source keys directly, keeps the entry.

A downstream process-capture tool hit this in morluto/rea#3338.

Ngôn ngữ chính
TypeScript
Star
2k
Fork
343
Merge trung bình
22 giờ 24 phút
Pull request đã merge (30 ngày)
6

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/node-pty

Tất cả issue của microsoft/node-pty

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.