Repository navigation
Conversation
`post_start_to_string` joined a devcontainer `postStartCommand` array
with ` && `. The devcontainer specification defines the array form as one
executable plus its arguments, without a shell, so joining both split
arguments into separate commands and gave shell metacharacters inside an
argument live meaning.
For the issue's example, `["printf", "%s\n", "hello world"]` became:
printf && %s
&& hello world
which runs `printf` with no arguments and fails. The same input now
renders as `'printf' '%s\n' 'hello world'`, which prints `hello world`,
and `["echo", "a && b", "$(id)"]` prints those two arguments literally
instead of chaining and substituting.
Build the array form with `RemoteCommand`, the same builder that already
escapes untrusted values once at the SSH boundary, so each element
arrives as a single word. The string form is shell text and is passed
through unchanged, so hooks that rely on pipes and `&&` keep working.
Replace `translate_post_start_array_joins`, which asserted the joining,
with coverage for argv preservation, spaces inside one argument, shell
metacharacters, and the untouched string form.
Fixes #515
|
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #515
What
post_start_to_stringjoins a devcontainerpostStartCommandarray with&&. The devcontainer specification defines the array form as one executable plus its arguments, without a shell — so joining both splits arguments into separate commands and gives shell metacharacters inside an argument live meaning.The issue's example:
{"postStartCommand": ["printf", "%s\n", "hello world"]}currently renders as:
which runs
printfwith no arguments and fails. The same input now renders as'printf' '%s\n' 'hello world', which printshello worldfollowed by a newline.The change
src/devcontainer.rs::post_start_to_stringnow builds the array form withRemoteCommand— the same builder that already escapes untrusted values exactly once at the SSH boundary — so each element arrives as a single word instead of a separate command. The string form is authored shell text and passes through unchanged, so hooks relying on pipes and&&keep working.docs/devcontainer.mddescribed the old behavior ("arrays are joined with&&"), and theInvalidreport message for a malformed value quoted it, so both are updated.Tests
translate_post_start_array_joinsasserted the joining, so it is replaced by four tests: argv preservation, a space inside one argument, shell metacharacters, and the string form staying untouched.The issue asks for coverage of spaces and shell metacharacters in arguments; that is what the new tests pin:
Verification
cargo test --lib devcontainer::— 67 passed, 0 failed.cargo test— 1258 passed, 1 failed, and that one failure (proxy::tests::reverse_forward_rejects_a_live_ssh_without_an_established_connection) reproduces on a cleanmainwithout this change, so it is unrelated.cargo fmt --checkandcargo clippy --all-targets -- -D warningsare both clean.I also ran the rendered commands through a shell to confirm the end-to-end behavior rather than only asserting on strings:
printf && %s\n && hello world→printf: usage: printf format [arg ...]'printf' '%s\n' 'hello world'→hello world'echo' 'a && b' '$(id)' 'it'\''s'→a && b $(id) it's(inert, not executed)Note
argv boundaries are preserved through to
run_post_start, which passes the rendered string toRemoteCommand::literalin the guest — correct here because every element is escaped exactly once at this boundary, and the string form remains trusted shell text.One adjacent case I left alone since it predates this issue and is unchanged by it: an empty array (
"postStartCommand": []) still yields an empty command string. Worth a separate issue if it matters.