Skip to content

Commit 96404be

Browse files
dhhclaude
andcommitted
Catch a privileged heredoc redirected with >|
`>|` is a plain redirect with noclobber overridden, not a redirect followed by a pipe. command_destinations detached `>` from its target before looking at the bar, so the target read as `|` and the privileged path behind it was never examined: `cat <<EOF >| /etc/udev/rules.d/99-x.rules` with `$HOME` in the body produced no finding at all, while the same write through `>` produced one. Normalizing `>|` to `>` alongside the existing `>>` handling closes it. The fixture fails without the normalization. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 844f320 commit 96404be

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# `>|` is a plain redirect with noclobber overridden, not a redirect into a pipe.
2+
cat >|/etc/omarchy/agent.conf <<EOF
3+
helper=$HOME/.local/share/omarchy/bin/omarchy-agent
4+
EOF

‎test/shell.d/privileged-heredoc-test.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ command_destinations() {
380380
# contain spaces anywhere this check runs.
381381
line=${line//\"/ }
382382
line=${line//\'/ }
383+
# `>|` overrides noclobber; the bar belongs to the operator, not to a pipe.
384+
# Left alone it becomes the redirect's target and hides the privileged path
385+
# behind it, so a `cat <<EOF >| /etc/...` heredoc reports no destination.
386+
line=${line//">|"/">"}
383387
# Preserve append redirects before detaching redirect operators from their
384388
# targets, so ">> /etc/x" does not become two ">" tokens whose first target
385389
# is the second operator.
@@ -922,6 +926,8 @@ fixture_flags route-prebody-escaped-pipeline.sh \
922926
"flags an escaped-line pipeline consumer before the heredoc body"
923927
fixture_flags route-dash-delimiter.sh "flags an indented <<- heredoc"
924928
fixture_flags route-append-redirect.sh "flags an append redirect into /etc"
929+
fixture_flags route-noclobber-redirect.sh \
930+
"flags a noclobber-override redirect into /etc"
925931
fixture_flags arithmetic-left-shift-before-heredoc.sh \
926932
"an arithmetic left shift does not swallow a later privileged heredoc" \
927933
"path-shaped expansions: HOME"

0 commit comments

Comments
 (0)