Skip to content

fix: CDK app fails to launch if paths contain spaces #645

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jun 19, 2025

When executing CDK apps, users specify the command as a string. The only feasible interpretation of that is by executing the command line through a shell, either bash or cmd.exe. We are using shell execution on purpose; it's used for tests, it's necessary on Windows to properly execute .bat and .cmd files, and since we have historically offered it you can bet dollars to doughnuts that customers have built workflows depending on that.

Note that the source of the string and the machine it's executing on are part of the same security domain: it's all "the customer". The customer writes the command string, then executes it on their own machine. Customers don't build strings from untrusted sources.

However, in code we did do trivial parsing of that string to string[], do some manipulation, and then combine it back to a string, by doing splitting and joining on " ". This led to an error on Windows systems where we would build an invalid command line if the path points to a .js file and the path to the Node interpreter has spaces in it (C:\Program Files) (or the path of the .js file itself).

Instead of splitting and joining on on " ", in this PR we parse and join according to the rules of the shell (be it either POSIX-compatible or cmd.exe-compatible). This is quite tricky and it might be incorrect. Still, we are not doing this with the goal of nullifying the active shell characters; we are just trying to account for quotes and spaces.

This PR fixes several instances where we were building a command line by joining an array of command line arguments with spaces. This would then cause problems if any of the parts of the command line contain spaces themselves, because we have lost information about the argument separators.

Instead, keep the structure information (keeping the command line in string[] form as long as possible) so that on Windows, where spaces in command lines are common, executions don't fail.

Closes #636


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

@rix0rrr rix0rrr requested a review from a team June 19, 2025 09:25
@aws-cdk-automation aws-cdk-automation requested a review from a team June 19, 2025 09:25
@github-actions github-actions bot added the p2 label Jun 19, 2025
@rix0rrr rix0rrr changed the title fix: CDK app launches fail if paths contain spaces fix: CDK app fails to launch if paths contain spaces Jun 19, 2025
@github-actions github-actions bot added bug effort/small <1 day of work p1 and removed p2 labels Jun 19, 2025
@rix0rrr rix0rrr temporarily deployed to integ-approval July 7, 2025 11:22 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-cdk: cdk synth/deploy command fails with "C:\Program" is not recognized as an internal or external command
3 participants