Skip to content

chore: ban direct child_process and shell:true outside the subprocess tool - #1902

Open
iankhou wants to merge 1 commit into
mainfrom
iankhou-ban-direct-child-process
Open

chore: ban direct child_process and shell:true outside the subprocess tool#1902
iankhou wants to merge 1 commit into
mainfrom
iankhou-ban-direct-child-process

Conversation

@iankhou

@iankhou iankhou commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

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.

  • no-restricted-imports: ban child_process / node:child_process
  • no-restricted-syntax: ban shell: true in spawn options

Spawn paths have to go through run/runSync/runUserCommandLine from the subprocess tool. The tool itself carries a localized eslint-disable at the two sanctioned lines.

Test files are exempt (they mock/spy on child_process). integ-runner and cli-integ have temporary, tracked per-file overrides pending their migrations. cdk-build-tools is 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_process import into a migrated lib/ file, and the rule fires as expected. Obviously did not keep that import.

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@iankhou
iankhou deployed to automation August 26, 2026 17:46 — with GitHub Actions Active
@iankhou
iankhou deployed to automation August 26, 2026 17:46 — with GitHub Actions Active
@iankhou
iankhou marked this pull request as ready for review August 26, 2026 17:46
@github-actions github-actions Bot added the p2 label Aug 26, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 26, 2026 17:46
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov-commenter

codecov-commenter commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.27%. Comparing base (d51353e) to head (a85820c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1902      +/-   ##
==========================================
- Coverage   91.39%   91.27%   -0.12%     
==========================================
  Files          79       79              
  Lines       12139    12139              
  Branches     1728     1720       -8     
==========================================
- Hits        11094    11080      -14     
- Misses       1010     1024      +14     
  Partials       35       35              
Flag Coverage Δ
suite.unit 91.27% <ø> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iankhou
iankhou force-pushed the iankhou-ban-direct-child-process branch from c40d964 to 5dd2235 Compare August 26, 2026 18:15
@iankhou
iankhou force-pushed the iankhou-ban-direct-child-process branch from 5dd2235 to a626b51 Compare August 26, 2026 18:26
@iankhou
iankhou deployed to no-approval August 26, 2026 18:26 — with GitHub Actions Active
@iankhou
iankhou deployed to no-approval August 26, 2026 22:17 — with GitHub Actions Active
@iankhou
iankhou deployed to run-tests August 26, 2026 22:22 — with GitHub Actions Active

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds ESLint safeguards to centralize subprocess execution in the shared utility.

Changes:

  • Restricts direct child_process imports and shell: 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.

Comment thread projenrc/eslint/team.ts
// The only sanctioned shell entry point is `runUserCommandLine` in the
// subprocess tool (which carries its own eslint-disable); everything else
// must spawn an argv array via `run`/`runSync`, which never touch a shell.
selector: "Property:matches([key.name='shell'], [key.value='shell'])[value.value=true]",
Comment thread .projenrc.ts
Comment on lines +1575 to +1578
rules: {
'no-restricted-imports': ['off'],
'no-restricted-syntax': ['off'],
},
Comment on lines +27 to +31
message: 'Do not use `child_process` directly. Use `run`/`runSync`/`runUserCommandLine` from the subprocess tool (\'./private/tools\').',
},
{
name: 'node:child_process',
message: 'Do not use `child_process` directly. Use `run`/`runSync`/`runUserCommandLine` from the subprocess tool (\'./private/tools\').',
Comment thread .projenrc.ts
Comment on lines +1704 to +1707
// cli-integ is a test harness that deliberately spawns through a shell (and a
// pty) to exercise the CLI the way a user would at a terminal — that is the
// point of these helpers, not something to migrate away. Permanently exempt,
// like test code. Scoped to the current sinks so NEW files still hit the ban
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: prevent shell execution outside of the shared subprocess utilities

3 participants