-
Notifications
You must be signed in to change notification settings - Fork 0
chore: bring code comments in line with the no-comments rule #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f9756ce
chore(docs): record auto-update security model and comment salvage
bhagyamudgal 6d28269
chore(src): remove comments that restate the code
bhagyamudgal 01f11a9
chore(docs): adopt the no-comments rule for this project
bhagyamudgal a58e56b
fix: align ADR contract with implementation and complete throttle cit…
bhagyamudgal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| node_modules/ | ||
| dist/ | ||
| .worktrees | ||
| docs/ | ||
| tasks/ |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # ADR: auto-update security model | ||
|
|
||
| Status: accepted. | ||
|
|
||
| Worktree-cli self-updates by downloading compiled binaries from GitHub | ||
| releases in a background child process and swapping them in on the next | ||
| launch. The updater fetches over the network, writes executables, and runs | ||
| them, so every input is untrusted until verified. | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| ## 1. Threat model | ||
|
|
||
| Attackers considered: a network adversary off GitHub origins, a compromised | ||
| CDN or release asset, a tampered SHA256SUMS file, a local user planting | ||
| symlinks in shared install dirs, and stale or rolled-back stages. | ||
| Non-goals: defending a machine whose running binary is already compromised, | ||
| and hiding version numbers. | ||
|
|
||
| ## 2. Host pinning and redirects | ||
|
|
||
| Fetches go only to allowlisted GitHub hosts: api.github.com, github.com, | ||
| codeload.github.com, objects.githubusercontent.com, | ||
| release-assets.githubusercontent.com, and | ||
| github-releases.githubusercontent.com. The check compares URL.host and does | ||
| not require HTTPS. Redirects are followed manually so each hop's host is | ||
| validated before connecting. Authorization is stripped once the host differs | ||
| from the first URL's host and never re-added, so a chain that bounces back | ||
| to the starting host cannot re-attach the token; a same-host scheme change | ||
| does not strip it. Redirect refusals log the host only, because signed CDN | ||
| URLs can carry tokens in the query string, while the initial | ||
| disallowed-host refusal logs a truncated URL. | ||
|
|
||
| ## 3. Size caps | ||
|
|
||
| Asset downloads are capped at 200 MB, which is headroom over the current | ||
| ~50 MB binary, and oversized responses are rejected before verification. | ||
| Chunks stream to disk with the cap enforced as bytes arrive instead of | ||
| buffering the whole body in memory. | ||
|
|
||
| ## 4. Release metadata and checksums | ||
|
|
||
| Release tags must match a strict version pattern before they are used in | ||
| paths or logs. The SHA256SUMS parser lowercases hex, skips blanks and | ||
| `#` comments, rejects BSD-tagged `SHA256 (file) = hex` lines, and treats | ||
| duplicate entries as tampering. Tamper (parsed but malformed sums) is a | ||
| distinct outcome from fetch errors: tamper escalates loudly and burns the | ||
| throttle, while fetch errors retry when transient. Retryable statuses are | ||
| 5xx plus 403 and 429, which are the GitHub rate-limit signals; other 4xx are | ||
| permanent. In the background path, releases without SHA256SUMS fall back to | ||
| a self-hash recorded in the sidecar, which detects local stage-to-apply | ||
| corruption only, not upstream tampering; the foreground updater instead | ||
| proceeds without hash verification and says so. | ||
| Requests identify as worktree-cli and use GITHUB_TOKEN when present, since | ||
| authenticated calls get a far higher rate limit than anonymous ones. | ||
|
|
||
| ## 5. Staging and apply integrity | ||
|
|
||
| Temp and sidecar files are pre-unlinked so writes cannot follow planted | ||
| symlinks. Verification runs before chmod and before the probe, because | ||
| executing an unverified binary is code execution. The probe requires the | ||
| staged binary to run `--version` successfully with version-shaped output, | ||
| because a hash match does not prove runnability, and it runs with | ||
| auto-update disabled so the probe cannot spawn grandchildren or consume a | ||
| stale stage. The sidecar writer is locked to the reader's version and hash | ||
| pattern so a future parser relaxation cannot turn a crafted tag into a hash | ||
| spoof. A stage older than the running version is discarded as stale, since a | ||
| foreground update may have raced a background check, and applying it would | ||
| silently downgrade. Hash comparison is constant-time to close the timing | ||
| side channel, and the sums object has a null prototype to block `__proto__` | ||
| pollution from a tampered file. | ||
|
|
||
| ## 6. Throttle policy | ||
|
|
||
| A completed check burns the 24h throttle window on structural or permanent | ||
| outcomes, so a broken release does not cost a download or API call on every | ||
| launch. Transient outcomes keep retrying: a missing arch asset (the | ||
| maintainer may upload it later), transient sums errors, local hash I/O | ||
| errors, and sidecar or stage writes that fail for non-permission reasons. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Comment salvage | ||
|
|
||
| Facts removed from code comments because the no-comments rule allows only | ||
| one-line citations. Each entry names the file and symbol it came from. Prune | ||
| this file by verifying each fact and either citing a source or deleting it. | ||
|
|
||
| ## src/lib/editor.ts / resolveEditor | ||
|
|
||
| - clack's select returns string | symbol, but isCancel narrows the symbol | ||
| case above. | ||
|
|
||
| ## src/lib/git.ts / selectWorktree | ||
|
|
||
| - p.select returns string | symbol, but isCancel above exits on symbol, and | ||
| library types do not narrow. | ||
|
|
||
| ## src/lib/auto-update.ts / scheduleBackgroundUpdateCheck | ||
|
|
||
| - POSIX setsid(): survives terminal close so a slow download isn't SIGHUPed. | ||
| - Close parent's fd copy even if Bun.spawn throws synchronously (else fd | ||
| leak per launch). | ||
|
|
||
| ## src/lib/auto-update.ts / probeBinaryRuns | ||
|
|
||
| - Bun.spawnSync returns null exitCode on timeout kill. | ||
|
|
||
| ## src/lib/auto-update.ts / decodeProbeStream | ||
|
|
||
| - Emit a debuggable marker (not "") so a Bun API shape change is visible in | ||
| last-error. | ||
|
|
||
| ## src/lib/config.ts / readConfigFile | ||
|
|
||
| - file.exists() can throw on stat errors. | ||
|
|
||
| ## src/lib/config.ts / shouldAutoUpdate | ||
|
|
||
| - file.exists() can throw EACCES. | ||
|
|
||
| ## src/lib/fs-utils.ts / classifyWriteError | ||
|
|
||
| - Walks cause chain for errno; EBUSY/ETXTBSY treated as permanent (file | ||
| locked/busy). | ||
|
|
||
| ## src/lib/release.ts / withTimeout | ||
|
|
||
| - Drain the redirect body so keep-alive sockets don't pin across hops. |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.