Skip to content

Cut the host-defaults installer windows from structure, not from comments - #9662

Merged
danielhanchen merged 2 commits into
mainfrom
harden-host-defaults-installer-windows
Aug 25, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
harden-host-defaults-installer-windows

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #9655, which replaced the README heading slice in tests/sh/test_install_host_defaults.sh with a structural probe. Four sibling windows were inventoried at the time and deliberately left alone. This does those four.

The security property is unchanged and is not weakened anywhere: the installers and README must not put a wildcard bind (0.0.0.0, [::], ::) in a default launch command, and the LAN opt-in must still be documented as an opt-in. This is about how the file finds the region it asserts on.

What was wrong

Three of the four windows ran to end of file, so each negative assertion covered a superset of the region its label named. Two of them were anchored on comment prose:

window old anchor kind
install.sh launcher /cat > "\$_css_launcher"/ + a second grep for the terminator code, but two patterns
install.sh end block /In interactive terminals/ comment
install.ps1 end block /In interactive terminals/ comment
studio/setup.sh hint /"launch"/ printed label

A comment is the worst possible anchor, because a comment exists to be rewritten. Rewording either of those two turns this guard red on an edit that has nothing to do with host defaults, which is how it took main red twice already.

The one that could go quiet

The launcher window is not just fragile. It can go vacuous, and I have a reproduction on b3d86b2d0.

It found its start with an awk pattern that matched cat > "$_css_launcher", and found its terminator with a separate, stricter grep that also required the << on that same line. Wrap the redirect across a line continuation, which is a formatting change and nothing more:

cat > "$_css_launcher" \
    << 'LAUNCHER_EOF'

The grep now matches nothing, so the derived delimiter is the empty string, so $0 == delim matches the first blank line inside the heredoc. The window collapses from 357 lines to 6. The #!/usr/bin/env bash canary sits inside those 6 and still passes.

With that reformat in place I changed the launcher's own launch line to

exec "$UNSLOTH_EXE" studio -H 0.0.0.0 -p "$_launch_port"

so every TTY launch of the installed Studio binds the LAN, and the suite reported PASS: 39 / FAIL: 0 / ALL PASSED. On this branch the same tree reports 2 failures.

To be clear about the scope: this is the only one of the four that can be quiet. The other three fail loudly on a marker reword. Their cost is a red on main from an unrelated edit, plus the end-of-file over-reach, not a blind guard.

What replaces them

Each window is now cut from the file's own structure.

install.sh launcher is the heredoc, bounded by its own delimiter, where the start and the terminator come from the same matched line in the same helper. There is no second pattern left to disagree with the first. The helper also joins backslash continuations while it is looking for the opener, so the redirect and its << are matched as one shell logical line however they are wrapped, and it stops joining the moment the heredoc opens, because the launcher body has continuations of its own and those are content.

install.sh end block is the top-level if that declares the post-install branch, through the fi in column zero that closes it, anchored on _SKIP_AUTOSTART rather than on the comment above it.

install.ps1 end block is the if ($IsInteractive) { block, through the line where its braces balance again.

studio/setup.sh is deliberately not windowed, and the label says so. Its footer sits in a top-level if [ "$_LLAMA_ONLY" = "1" ]; then block, and that same header opens three different top-level blocks in that file, so no structural boundary picks out the footer, only the ordinal "the third one", which is a hand-written marker wearing a different hat. The old anchor ran to end of file from "launch" anyway, so reading the whole file loses no coverage and gains the rest of it. Over-reporting there is cheap: the file's own wildcard opt-in is prose (add -H 0.0.0.0 for LAN / cloud access) with no studio word in it, so it is not a launch command and does not trip this.

Every window now asserts that it closed on its own closing token (LAUNCHER_EOF, fi, }). That is what turns a close that never matched into a report instead of a silent run to end of file, and it is the assertion that would have caught the vacuity above.

Two whole-file backstops were added for install.sh and install.ps1. The windows name the region each guard is about, which is what makes a failure readable; the backstops name the file, which is what makes the family hard to defeat. Both installers are clean today because their opt-in text is prose rather than a runnable command.

Both directions, per window

Every mutation was applied to a byte snapshot and restored with md5 confirmation, never with git checkout --. Each row was run against the origin/main guard and this branch's guard on the same mutated tree.

case mutation old guard this branch
W1-a wildcard on the generated launcher's exec line RED 38/1 RED 43/2
W1-b heredoc opener wrapped onto a line continuation GREEN (blind) GREEN 45/0
W1-c that wrap plus the wildcard on exec GREEN 39/0 RED 43/2
W1-d delimiter renamed LAUNCHER_EOF -> STUDIO_LAUNCH_EOF GREEN GREEN 45/0
W1-e space dropped: cat >"$_css_launcher" << RED 38/1 GREEN 45/0
W2-a wildcard in the non-interactive substep hint RED 38/1 RED 43/2
W2-b reword In interactive terminals RED 38/1 GREEN 45/0
W2-c delete that comment block entirely RED 38/1 GREEN 45/0
W2-d --host=0.0.0.0 on the interactive autostart exec RED 38/1 RED 43/2
W3-a wildcard in the ps1 non-interactive hint RED 38/1 RED 43/2
W3-b reword the ps1 In interactive terminals comment RED 38/1 GREEN 45/0
W3-c wildcard in the ps1 Start-Process arg list RED 38/1 RED 43/2
W4-a wildcard in the setup.sh footer hint RED 38/1 RED 44/1
W4-b printed label "launch" renamed to "start" RED 38/1 GREEN 45/0
W4-c wildcard added above the old window's start GREEN 39/0 RED 44/1
blind studio_commands() forced to return [] RED 24/15 RED 30/15

W1-c is the vacuity. W1-b, W1-e, W2-b, W2-c, W3-b and W4-b are the reds this removes. W1-e and W4-c are coverage the old windows did not have. The blinding row is the anti-vacuity check on the detector itself: forcing the shared matcher to see nothing produces 15 failures, not a quiet green.

Counts

39 pass / 0 fail before, 45 pass / 0 fail after. The six new assertions are three window-closed checks, one "a heredoc terminator was derived" canary, and the two whole-file backstops.

No installer, README or CLI file is touched; the diff is this one test file. shellcheck -e SC1090,SC2034 and bash -n, the two checks lint-ci runs over committed shell, are both clean.

…ents

tests/sh/test_install_host_defaults.sh sliced install.sh, install.ps1 and
studio/setup.sh on hand-written markers, two of which were comment prose. A
comment exists to be rewritten, so this guard went red twice for reasons that
had nothing to do with host defaults, and three of the four windows ran to end
of file, so each negative assertion covered more than its label claimed.

The launcher window was worse than fragile: it could go vacuous. It found its
start with an awk pattern and its terminator with a separate, stricter grep that
also required the << on the same line. Wrap that redirect across a line
continuation and the grep matches nothing, the derived delimiter is the empty
string, and $0 == delim then matches the first blank line inside the heredoc.
The window collapses from 357 lines to 6, the shebang canary sits inside those 6
and still passes, and a -H 0.0.0.0 on the launcher's own exec line reports 39
pass / 0 fail.

Each window is now cut from the file's own structure: the heredoc's own
delimiter, read off the same matched line that opens it; the top-level if that
declares the post-install branch; the PowerShell brace block. Every one asserts
it closed on its own closing token, so a close that never matched is a report
rather than a silent run to end of file. studio/setup.sh is read whole and
labelled as such, because its footer header opens three different top-level
blocks and no structural boundary picks out the right one. Two whole-file
backstops catch a wildcard bind that lands outside every window.

39 pass / 0 fail before, 45 pass / 0 fail after.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c96a50219d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

_ps_brace_block() {
awk -v pat="$2" '
!found && $0 ~ pat { found = 1 }
found { print; depth += gsub(/[{]/, "&") - gsub(/[}]/, "&"); if (depth <= 0) exit }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ignore non-syntactic braces in the PowerShell block parser

When a comment or quoted string inside the inspected $IsInteractive block contains an unmatched brace—for example, a diagnostic string that mentions }—gsub treats it as PowerShell structure and may terminate the window early. The closing-token assertion then fails even though the installer behavior and host defaults are unchanged, recreating the behavior-preserving-comment-edit failure this change is intended to eliminate; strip comments/strings or use PowerShell's parser when balancing braces.

Useful? React with 👍 / 👎.

"studio/setup.sh: the launch hint binds no wildcard host" \
"$_setup_tail"
"install.ps1: no launch command anywhere in the file binds a wildcard host" \
"$(cat "$INSTALL_PS1")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude PowerShell block comments from the whole-file scan

When install.ps1 contains a <# ... #> block comment before the end-of-install block with an example such as unsloth studio --host 0.0.0.0, this new whole-file assertion reports it as a launch command even though PowerShell never executes or prints it. The probe removes only # line comments, so applying it to the entire raw source introduces false CI failures for behavior-preserving documentation or commented-out examples; strip PowerShell block comments before scanning.

Useful? React with 👍 / 👎.

sub(/^[ \t]+/, " ", nxt)
line = line nxt
}
if (!index(line, target) || !index(line, "<<")) next

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require an actual redirect when selecting the heredoc opener

When any earlier comment or unrelated line contains both _css_launcher and a heredoc example such as <<'EXAMPLE', this substring check selects that line instead of the real launcher redirect. The derived delimiter then differs from the launcher's terminator and the test fails on an installer behavior-preserving comment edit—the exact instability this helper is intended to remove; ignore comments and verify that the target is the heredoc's redirection destination.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit fda287d into main Aug 25, 2026
15 checks passed
@danielhanchen
danielhanchen deleted the harden-host-defaults-installer-windows branch August 25, 2026 03:15
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.

1 participant