Harden command execution in init wizard beyond string-based validation
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- node.js, shell, typescript
- 領域
- cli, operating-systems, security
調査の方向性
cli/src/lib/init/local-ops.ts を読み、まず validateCommand() と runSingleCommand() から、既存の検証、シェルの使用、タイムアウト、出力制限を理解してください。issue に記載されている Linux と macOS の sandboxing オプションを比較し、どのコマンドパスに OS 固有の処理が必要かを判断してください。既存のチェックを削除せずに選択した hardening アプローチが実装され、そのセキュリティ境界が検証されていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
cli/src/lib/init/local-ops.ts executes commands from the API server using shell: true. The current protections are string-based and could be bypassed by a sufficiently creative payload. Before sentry init exits experimental mode, we should add OS-level sandboxing.
Current protections
validateCommand() (line 140) — three layers of string validation:
- Shell metacharacter blocking — rejects commands containing
;,&&,||,|,`,$(,$, quotes, redirects (>,<), braces, globs, newlines, backslashes - Env var injection blocking — rejects commands where the first token contains
= - Dangerous executable blocklist — rejects 40+ executables (
rm,curl,sudo,ssh,bash,eval, etc.) but only checks the first token — e.g.npm exec -- rm -rf /would pass becausenpmis the primary executable
safePath() / path validation — prevents path traversal and symlink escapes outside the project root.
runSingleCommand() (line 426) — spawns via spawn(command, [], { shell: true, cwd, ... }) with a timeout and output truncation (64KB cap).
Gap
All protections are string-based pattern matching. The command still runs under shell: true with full user privileges. Potential bypasses:
- Package manager subcommands that execute arbitrary code (e.g.
npm exec, lifecycle scripts) - Unicode/encoding tricks that survive validation but are interpreted differently by the shell
- Future commands the server might send that don't match current patterns
Suggested hardening (Linux)
These are additive layers — the string validation remains as a fast first pass.
| Technique | How | Benefit |
|---|---|---|
Linux namespaces / unshare |
unshare --net --mount --pid wrapper |
Network isolation, mount isolation, PID isolation |
| Landlock LSM | Restrict filesystem access to project dir + node_modules + package manager cache | Prevents reads/writes outside expected paths even if shell escapes |
bubblewrap (bwrap) |
Lightweight sandbox with readonly / bind-mount, writable project dir only |
Strong filesystem + namespace isolation in one tool |
| Drop to restricted user | runuser / setuid to a no-login user for spawned commands |
Limits damage from any escape |
| Read-only filesystem mounts | Bind-mount / as read-only, whitelist project dir as writable |
Commands can't modify system files |
| Network namespace isolation | Empty network namespace for commands that don't need network (e.g. codemods) | Prevents data exfiltration |
--shell=false where possible |
For simple commands like npx @sentry/wizard, split into [executable, ...args] and avoid shell entirely |
Eliminates shell injection surface |
macOS considerations
macOS lacks namespaces/Landlock. Options are more limited:
sandbox-exec(deprecated but functional) with a restrictive profile- Avoid
shell: truewhere possible by splitting commands into argv arrays
Priority
Low — the current string validation is a reasonable defense for an experimental feature where commands originate from our own API server. This becomes more important if/when the command surface expands or the feature exits experimental.
- 主要言語
- TypeScript
- スター
- 121
- フォーク
- 14
- 平均マージ
- 23時間 54分
- マージ済み PR(30日)
- 103
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
getsentry/cli のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
-
bug jared
-
jared
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
bug v2
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
modelcontextprotocol/inspector#2458 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
carbon-design-system/ibm-products#9907 ·