-
Notifications
You must be signed in to change notification settings - Fork 481
fix(eslint): detect inline require('child_process').<method>() in no-child-process-interpolated-command #49069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,7 +133,14 @@ function resolveChildProcessMethod(node: TSESTree.CallExpression, sourceCode: TS | |
| } | ||
|
|
||
| if (callee.type !== AST_NODE_TYPES.MemberExpression || callee.computed) return null; | ||
| if (callee.object.type !== AST_NODE_TYPES.Identifier || callee.property.type !== AST_NODE_TYPES.Identifier) return null; | ||
| if (callee.property.type !== AST_NODE_TYPES.Identifier) return null; | ||
|
|
||
| if (callee.object.type === AST_NODE_TYPES.CallExpression && isRequireChildProcess(callee.object)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reusing 💡 DetailsThis extends the same flawed name-matching helper already noted in an earlier review comment on line 141 (for the identifier-binding path) to a new call site — doubling the false-positive exposure. Example: function run(require, input) {
require("child_process").execSync(`echo ${input}`);
}A proper fix would have |
||
| const method = callee.property.name; | ||
| return method === "exec" || method === "execSync" || method === "spawn" || method === "spawnSync" || method === "execFile" || method === "execFileSync" ? method : null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method-validation ternary here is identical to the one on line 147. Both inline the same 6 methods that also appear in the @copilot please address this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method allow-list ternary is now duplicated verbatim on lines 140 and 147, so a future edit to the supported method set only touching one copy silently reintroduces a gap. 💡 DetailsBoth branches repeat: return method === "exec" || method === "execSync" || method === "spawn" || method === "spawnSync" || method === "execFile" || method === "execFileSync" ? method : null;A const CHILD_PROCESS_METHOD_NAMES = new Set<ChildProcessMethod>(["exec","execSync","spawn","spawnSync","execFile","execFileSync"]);
function asChildProcessMethod(name: string): ChildProcessMethod | null {
return CHILD_PROCESS_METHOD_NAMES.has(name as ChildProcessMethod) ? (name as ChildProcessMethod) : null;
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] The method-name whitelist on this line is duplicated verbatim on line 147 — both paths use the same inline ternary. If a new method is added to one but not the other, the rule silently misfires. 💡 Suggested refactor
const CHILD_PROCESS_METHODS = new Set<string>(["exec", "execSync", "spawn", "spawnSync", "execFile", "execFileSync"]);
// replace both ternaries with:
return CHILD_PROCESS_METHODS.has(method) ? (method as ChildProcessMethod) : null;This keeps both code paths in sync automatically. @copilot please address this. |
||
| } | ||
|
Comment on lines
+138
to
+141
|
||
|
|
||
| if (callee.object.type !== AST_NODE_TYPES.Identifier) return null; | ||
| if (!isChildProcessObjectBinding(callee.object.name, callee.object, sourceCode)) return null; | ||
|
|
||
| const method = callee.property.name; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] The new invalid test cases cover
exec/execSyncandspawn, butexecFile,execFileSync, andspawnSyncwith inlinerequire()are not exercised. Since the method list on line 140 now handles all six methods for the inline-require path, missing tests leave that coverage gap invisible.💡 Suggested additional test cases
@copilot please address this.