Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

spawn drops an own `__proto__` environment entry

未关闭 适合新手
#993 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@nikolay-dementiev 已经在做这个了。

开始于 2026年10月15日。

  • #994 来自 @nikolay-dementiev —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
nodejs, typescript

调研方向

从 src/utils.ts 中的 assign 辅助函数开始,它通过普通属性赋值把 options.env 复制到目标对象中,因此自有的 __proto__ 键会触发原型的 setter。顺着 spawn 如何把该 env 传给 _parseEnv 的路径往下看。运行 issue 中的复现步骤,检查子进程是否输出 true:selected-value。当一个 __proto__ 条目在复制后仍然保留(使用 defineProperty 或等效方法),并且复现通过时,即完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
2k
派生
343
平均合并
22 小时 24 分钟
30 天内合并 PR
6

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/node-pty 的其他 Issue

查看 microsoft/node-pty 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。