Commit 4aa84f2
Backport of #26235 to `release/2.29`.
- Original PR: #26235 (fix(agent/agentcontainers): prevent command
injection in shell execer)
- Merge commit: 112c921
`commandEnvExecer.prepare` rebuilt commands into a single shell string
using `fmt.Sprintf("%q", arg)`, which produces Go string literals rather
than shell-quoted tokens. Go's `%q` does not escape `$`, backticks, or
other metacharacters that stay active inside double quotes, so an
argument such as `$(...)` was evaluated by the shell as command
substitution. The fix passes the command to the shell as positional
parameters and runs `"$@"` so the shell forwards argv verbatim.
<details>
<summary>Backport notes</summary>
The cherry-pick (`git cherry-pick -x 112c921`) auto-merged context
differences in `execer.go` and `api_test.go` cleanly. The only manual
adaptation was in the new `execer_internal_test.go`: its imports were
changed from `cdr.dev/slog/v3` to `cdr.dev/slog`, because `release/2.29`
predates the slog v3 migration. No functional changes.
Verified on `release/2.29`:
- `go build ./agent/agentcontainers/` passes
- `go test ./agent/agentcontainers/ -run TestCommandEnvExecer_Prepare`
passes (3 subtests)
- `go test ./agent/agentcontainers/ -run TestAPI/CommandEnv` passes
</details>
> [!NOTE]
> Generated by Coder Agents on behalf of @f0ssel.
Co-authored-by: Zach <3724288+zedkipp@users.noreply.github.com>
1 parent a51dbcf commit 4aa84f2
3 files changed
Lines changed: 99 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2768 | 2768 | | |
2769 | 2769 | | |
2770 | 2770 | | |
2771 | | - | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
2772 | 2774 | | |
2773 | | - | |
2774 | | - | |
2775 | | - | |
2776 | | - | |
2777 | | - | |
2778 | | - | |
2779 | | - | |
2780 | | - | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
2781 | 2779 | | |
2782 | 2780 | | |
2783 | 2781 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | | - | |
8 | | - | |
9 | 6 | | |
10 | 7 | | |
11 | 8 | | |
| |||
51 | 48 | | |
52 | 49 | | |
53 | 50 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | 51 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
63 | 60 | | |
64 | 61 | | |
65 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
0 commit comments