chore: ban direct child_process and shell:true outside the subprocess tool - #1902
chore: ban direct child_process and shell:true outside the subprocess tool#1902iankhou wants to merge 3 commits into
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1902 +/- ##
==========================================
- Coverage 91.39% 91.30% -0.09%
==========================================
Files 79 79
Lines 12139 12139
Branches 1728 1722 -6
==========================================
- Hits 11094 11084 -10
- Misses 1010 1020 +10
Partials 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c40d964 to
5dd2235
Compare
5dd2235 to
a626b51
Compare
There was a problem hiding this comment.
Pull request overview
Adds ESLint safeguards to centralize subprocess execution in the shared utility.
Changes:
- Restricts direct
child_processimports andshell: true. - Adds scoped exemptions for tests and integration tooling.
- Regenerates package ESLint configurations.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
projenrc/eslint/team.ts |
Adds the shell restriction. |
projenrc/eslint/index.ts |
Configures test/build exemptions. |
projenrc/eslint/imports.ts |
Restricts child-process imports. |
.projenrc.ts |
Adds integration-tool exemptions. |
.eslintrc.json |
Regenerates root ESLint rules. |
packages/cdk/.eslintrc.json |
Regenerates package rules. |
packages/cdk-assets/.eslintrc.json |
Regenerates package rules. |
packages/aws-cdk/.eslintrc.json |
Regenerates CLI rules. |
packages/@aws-cdk/yarn-cling/.eslintrc.json |
Regenerates package rules. |
packages/@aws-cdk/user-input-gen/.eslintrc.json |
Regenerates package rules. |
packages/@aws-cdk/toolkit-lib/.eslintrc.json |
Regenerates toolkit rules. |
packages/@aws-cdk/private-tools/lib/subprocess/index.ts |
Exempts sanctioned subprocess operations. |
packages/@aws-cdk/private-tools/.eslintrc.json |
Regenerates private-tools rules. |
packages/@aws-cdk/integ-runner/.eslintrc.json |
Adds integ-runner exemption. |
packages/@aws-cdk/cloudformation-diff/.eslintrc.json |
Regenerates package rules. |
packages/@aws-cdk/cloud-assembly-schema/.eslintrc.json |
Regenerates package rules. |
packages/@aws-cdk/cloud-assembly-api/.eslintrc.json |
Regenerates package rules. |
packages/@aws-cdk/cli-plugin-contract/.eslintrc.json |
Regenerates package rules. |
packages/@aws-cdk/cdk-explorer/.eslintrc.json |
Regenerates package rules. |
packages/@aws-cdk/cdk-assets-lib/.eslintrc.json |
Regenerates package rules. |
packages/@aws-cdk-testing/cli-integ/.eslintrc.json |
Adds CLI integration exemptions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 28 out of 28 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
projenrc/eslint/imports.ts:28
no-restricted-importsonly checks static import/export declarations, so shipped code can still useawait import('node:child_process')and callexec/spawnoutside the shared wrapper. This leaves a direct bypass of the shell-consolidation guard; add coverage forImportExpression(for both specifiers), for example viano-restricted-syntaxor a dedicated rule.
name: 'child_process',
message: 'Do not use `child_process` directly. Use `run`/`runSync`/`runUserCommandLine` from the subprocess tool (\'./private/tools\').',
},
{
name: 'node:child_process',
- Broaden the shell-spawn ban: reject any `shell` property that is not
statically `false`, instead of only the literal `true`. `{ shell }`,
`shell: cond`, `shell: someVar` and `shell: '/bin/sh'` are now caught
(per review: matching only `true` left obvious bypasses).
- Replace the projen `addOverride` exemptions with in-file eslint-disable
comments that carry a reason at the spawn site:
- integ-runner/lib/utils.ts: exempt only the child_process import; the
shell rule stays active (exec() is argv-based today, so a future
shell:true there should still be caught).
- cli-integ: it is a test harness that intentionally spawns through a
shell to exercise the CLI as a user would — permanent, like test code.
…mption The test/build-tooling exemption previously turned no-restricted-imports and no-restricted-syntax fully off, which also dropped the pre-existing punycode and MD5 team rules there. Re-specify those two rules in the exemption so they keep applying, and drop ONLY the newer subprocess restrictions (child_process import + shell option). Extract PUNYCODE_IMPORT_RESTRICTION / MD5_SYNTAX_RESTRICTION as shared constants so the exemption reuses them without duplication.
Fixes #1903
Description
Locks in the subprocess consolidation (#1763, #1849) so new code or changes to existing code can't spawn shells outside the shared tool.
child_process/node:child_processshellspawn option — anyshellproperty that isn't staticallyfalse(so{ shell },shell: cond,shell: someVar,shell: '/bin/sh'are all caught, not just the literaltrue)Spawn paths have to go through
run/runSync/runUserCommandLinefrom the subprocess tool. The tool itself carries a localized eslint-disable at the two sanctioned lines.Test files and build tooling (
projenrc) are exempt. The two un-migrated shipped sinks carry in-fileeslint-disablecomments (each with a reason) at the spawn site rather than projen overrides:cli-integis a test harness that intentionally spawns through a shell to exercise the CLI as a user would (permanent, like test code), andinteg-runner'sexec()is argv-based/no-shell, so it exempts only thechild_processimport — theshellrule stays active there — with migration onto the shared tool deferred as follow-up.cdk-build-toolsis not managed by the root projen config, so the rule does not reach it yet; will address it in a follow-up.Testing
Inserted a
child_processimport into a migrated lib/ file, and the rule fires as expected. Obviously did not keep that import.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license