Skip to content

fix(devcontainer): keep postStartCommand arrays as argv - #526

Closed
Yi-111-a wants to merge 1 commit into
trailofbits:mainfrom
Yi-111-a:fix/devcontainer-post-start-argv
Closed

Yi-111-a wants to merge 1 commit into
trailofbits:mainfrom
Yi-111-a:fix/devcontainer-post-start-argv

Conversation

@Yi-111-a

@Yi-111-a Yi-111-a commented Oct 1, 2026

Copy link
Copy Markdown

Fixes #515

What

post_start_to_string joins a devcontainer postStartCommand array 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:

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 followed by a newline.

The change

src/devcontainer.rs::post_start_to_string now builds the array form with RemoteCommand — 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.md described the old behavior ("arrays are joined with &&"), and the Invalid report message for a malformed value quoted it, so both are updated.

Tests

translate_post_start_array_joins asserted 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:

translate_post_start_array_preserves_argv
translate_post_start_array_keeps_spaces_in_one_argument
translate_post_start_array_neutralizes_shell_metacharacters
translate_post_start_string_form_is_untouched

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 clean main without this change, so it is unrelated.

cargo fmt --check and cargo clippy --all-targets -- -D warnings are both clean.

I also ran the rendered commands through a shell to confirm the end-to-end behavior rather than only asserting on strings:

  • before: printf && %s\n && hello world → printf: usage: printf format [arg ...]
  • after: 'printf' '%s\n' 'hello world' → hello world
  • after: '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 to RemoteCommand::literal in 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.

`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
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@DarkaMaul

Copy link
Copy Markdown
Contributor

Thanks for the contribution! We removed devcontainer support in #535, so Coop no longer parses or executes postStartCommand arrays. The code this PR fixes is no longer present on main, and the related issue #515 was closed for that reason. I think we can close this PR as no longer applicable

@DarkaMaul DarkaMaul closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve argv semantics for devcontainer postStartCommand arrays

3 participants