fix/git: fail closed while preserving local dotfile credentials #3
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/witherbloom-safe-filters"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #2. Replace .env/sed OBS and OpenCode filters with required Python clean/smudge filters backed by a private 0700/0600 store. Also sanitize credential-shaped Pi settings fields. Installation captures current credentials without rewriting live files, installs a checkout-independent copy under the Git common directory, and refuses to replace unrelated pre-commit/pre-push hooks. Existing post-checkout hooks remain untouched. Commit checks inspect staged blobs; push checks inspect intermediate outgoing commits. Existing histories are not rewritten.
Four actual-Git integration tests pass: add/checkout restores quote/backslash-bearing secrets, required filter failures abort staging, JSONC/nested distinct headers round-trip, malformed JSON/missing state behavior, hooks block copied local secrets and intermediate leaked commits, existing hooks/symlinked private state refused. README documents limits and private backup location. Neocities pointers repaired separately with original file hashes unchanged. No live filter installation or working-tree replacement yet.
Additional read-only verification: 727 unique historical blobs reachable from the proposed head pass the new outgoing-tree checks (no existing-history cleanup required). Witherbloom SSH authentication now succeeds, and its existing gt OAuth credential helper passed a real HTTPS push dry run. Neocities worktree repair is complete with unchanged working-file hashes. Private pre-install backups prepared on Witherbloom; live credentials/filters not replaced pending exact-head review.
Pi code review
4 new actionable findings
scripts/dotfiles-secrets.py:121scripts/dotfiles-secrets.py:95scripts/dotfiles-secrets.py:176scripts/dotfiles-secrets.py:64Merged the candidate reviews of the credential filters, installer, hooks, tests and documentation at head
ff94781against base441e8a7. This was a read-only review; no tests or commands were run.Change walkthrough
.git-filters/obs-websocket-filter,.git-filters/opencode-api-keys,.gitattributesscripts/dotfiles-secrets.py,scripts/test_dotfiles_secrets.pyREADME.mdReview effort: 3/5.
Static observations (not validation results)
Reviewed
ff94781288b4469d5dcf0a55111dca71cb7782c7withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra. Automated advisory review; no project commands or tests were executed.@ -0,0 +61,4 @@def parse_json(text: str) -> Json:# JSONC is normalized to JSON (comments/trailing commas are not configuration).normalized = JSON_TOKEN.sub(lambda m: m.group() if m.group().startswith('"') else '', text)[P2] Comments after trailing commas make valid JSONC fail
Comment and trailing-comma removal happen in one substitution. When a comment separates a trailing comma from the closing delimiter, the comma remains after the comment is removed, and JSON parsing fails.
Trigger: An OpenCode JSONC configuration contains a trailing comma followed by a line or block comment before a closing object or array delimiter.
Impact: Installation fails to capture the configuration, and an installed required filter prevents staging it until the user changes its formatting.
Evidence: JSON_TOKEN matches a trailing comma only when whitespace immediately precedes the closing delimiter. parse_json() applies it once before json.loads(), while both transform() and the install capture loop depend on that parser. The test covers comments and trailing commas, but not a comment between the comma and delimiter.
@ -0,0 +92,4 @@values = load_store(directory)changed = Falsefor owner, key, address in credential_fields(data):identifier = profile + ':' + address[P2] OpenCode files overwrite each other's stored credentials
The store key contains the profile and JSON address but not the source file. Credentials at the same address in opencode.json and opencode.jsonc therefore share a slot, and cleaning either file overwrites the other value.
Trigger: Both OpenCode files exist with different credentials at the same JSON address; installation captures both, and the first file is later checked out.
Impact: Checkout restores the second file's credential into the first, potentially losing the first credential from the live file and private store and causing authentication failures.
Evidence: Both paths use the opencode-api-keys profile in PROFILES and .gitattributes. transform() constructs identifiers from only that profile and address, updates the shared slot on clean, and restores it on smudge; install() captures the two files in sequence.
@ -0,0 +118,4 @@def check_blob(path: str, data: bytes, known: list[bytes]) -> None:if TOKEN.search(data) or any(secret in data for secret in known):[P2] JSON-escaped copies of known credentials bypass both hooks
The known-secret check searches only for the decoded credential's raw bytes. JSON serialization escapes quotes and backslashes, so a copied credential containing either character can evade the check.
Trigger: A captured OBS or OpenCode credential containing a quote or backslash is serialized into an ordinary tracked JSON file outside the filtered profiles, and does not match a provider-token pattern.
Impact: The copied credential can be committed and pushed without bypassing either safety hook.
Evidence: check() encodes stored values directly, and check_blob() tests those bytes as substrings. It parses credential fields only for PROFILES paths; the copied-secret test writes the password as raw text rather than JSON-escaped text.
@ -0,0 +173,4 @@marker = '# dotfiles-secrets managed hook'for name in ('pre-commit', 'pre-push'):path = hooks / nameif path.is_symlink() or path.exists() and marker not in path.read_text():[P2] Reinstall overwrites manually integrated managed hooks
Any existing hook containing the managed marker passes the refusal check, but installation then replaces its entire contents.
Trigger: A user adds another check before the managed command in a pre-commit or pre-push hook, retains the marker, and reruns install as documented for tool updates.
Impact: The added hook logic is silently removed, potentially disabling other checks or protections.
Evidence: install() refuses a non-symlink hook only when its contents lack the marker, then unconditionally writes the bare managed hook at line 196. It does not check for user modifications.
Review #474: all four findings confirmed and fixed in
1c7dcef694. Known-secret checks now also compare JSON-escaped representations; private store keys include the source filename passed by Git %f; reinstall requires an exact managed hook match and refuses customized hooks; JSONC comment removal precedes trailing-comma removal. Five actual-Git integration tests pass, including escaped copied credentials in an ordinary JSON file, separate .json/.jsonc credentials, customized managed hooks, and comments after trailing commas. Live installation remains pending a clean exact-head review.Pi code review
1 new actionable finding
.git-filters/obs-websocket-filter:3Earlier findings: 4 rechecked
scripts/dotfiles-secrets.py:64, first reported in review #474) — parse_json() now removes comments before a separate trailing-comma substitution, so a comment between the comma and closing delimiter no longer prevents its removal.scripts/dotfiles-secrets.py:176, first reported in review #474) — install() compares each existing hook with the complete expected managed content and refuses customized hooks before writing them.scripts/dotfiles-secrets.py:121, first reported in review #474) — check_blob() now searches raw values and both Unicode-preserving and ASCII-escaped JSON representations; the copied-secret test serializes the quote- and backslash-bearing value as JSON.scripts/dotfiles-secrets.py:95, first reported in review #474) — The installed commands pass %f and use distinct source-based store keys, but the existing global compatibility command passes no filename. Both OpenCode paths therefore still share the first path's slot when that configuration is active before installation.Reviewed the filter wrappers, installer, hooks, tests, and documentation against the supplied base and head. No tests or live installation were run.
Change walkthrough
.git-filters/obs-websocket-filter,.git-filters/opencode-api-keys,.gitattributesREADME.mdscripts/dotfiles-secrets.py,scripts/test_dotfiles_secrets.pyReview effort: 3/5.
Static observations (not validation results)
Reviewed
1c7dcef694f0eacaba5c807847e5819527d2d702withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra. Automated advisory review; no project commands or tests were executed.@ -34,1 +1,3 @@esac#!/bin/sh# Compatibility entry point. Install required, checkout-independent filters first.exec python3 "$(dirname "$0")/../scripts/dotfiles-secrets.py" filter obs-websocket "$1"[P2] Legacy filter configuration can stage raw credentials after a filter failure
The replacement wrappers can fail on parsing or private-state errors, but the existing global filter configuration does not mark them required. Git can therefore stage the unfiltered file after a clean-filter failure.
Trigger: An existing clone uses the stowed .gitconfig definitions before the new installer has successfully configured local required filters, and a credential-bearing OBS or OpenCode file fails the Python clean step.
Impact: A password or API key can be committed and pushed in plaintext, despite the previous shell clean filter redacting the affected fields.
Evidence: .gitconfig defines clean and smudge commands without required=true; install() sets required only after credential capture succeeds. The new wrappers invoke the Python filter, which exits unsuccessfully on JSON or private-state errors, whereas the prior wrappers ran sed for clean operations.
Review #475 confirmed the remaining pre-install compatibility gaps. Fixed stowed .gitconfig to use source filenames (%f) and required=true for all three filters; removed implicit filename fallback from the CLI and made compatibility wrappers require it. Added a real-Git test proving stowed configuration aborts staging malformed credential JSON before installer execution. Six integration tests pass at
e14aa94; live installation still pending clean exact-head review.Pi code review
1 new actionable finding
.gitconfig:21Earlier findings: 2 rechecked
.git-filters/obs-websocket-filter:3, first reported in review #475) — The current stowed .gitconfig marks the OBS and OpenCode filters required, so a failing clean filter aborts staging rather than falling back to raw content. The installer also sets required=true locally..git-filters/opencode-api-keys:3, first reported in review #474) — The current .gitconfig passes %f to the OpenCode filter. transform() validates the source and includes it in the store key; the compatibility wrapper forwards the filename, and an omitted filename fails validation instead of defaulting both files to one slot.Reviewed the filter and installer changes against the supplied base, including both previous findings. Tests could not be run with the available read-only tools.
Change walkthrough
.git-filters/obs-websocket-filter,.git-filters/opencode-api-keys,.gitattributes,.gitconfigscripts/dotfiles-secrets.py,scripts/test_dotfiles_secrets.pyREADME.mdReview effort: 3/5.
Static observations (not validation results)
Reviewed
e14aa94a2bf4b9f212c3ece73276040e13bd8ec0withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra. Automated advisory review; no project commands or tests were executed.@ -20,1 +19,3 @@smudge = .git-filters/opencode-api-keys smudgeclean = python3 scripts/dotfiles-secrets.py filter opencode-api-keys clean %fsmudge = python3 scripts/dotfiles-secrets.py filter opencode-api-keys smudge %frequired = true[P2] Quality: Required global smudge filters abort fresh clones
Once the updated .gitconfig is stowed globally, a fresh clone needs the smudge script before that script has been checked out. The required filter therefore aborts the initial checkout, before the documented installer can configure its checkout-independent copy.
Trigger: A user with this stowed global .gitconfig runs an ordinary git clone of this repository into a new directory.
Impact: The clone is left with an incomplete working tree and requires manual recovery before installation can proceed.
Evidence: .gitconfig:20 invokes scripts/dotfiles-secrets.py relative to the new worktree, and line 21 makes failure fatal. .gitattributes applies this filter to the tracked .config/opencode/opencode.json, which is checked out before scripts/dotfiles-secrets.py. install() creates absolute local filter commands only afterward; the base configuration left the equivalent filter optional.
Review #476 fresh-clone failure confirmed and fixed in
214545ec81. Global bootstrap smudge is now pass-through; required clean still fails closed. Installer replaces both with absolute checkout-independent commands and private-value restoration. Added actual clone coverage under the stowed global config; six integration tests pass. README makes the install-before-edit requirement explicit.Pi code review
1 new actionable finding
scripts/dotfiles-secrets.py:183Earlier findings: 1 rechecked
.gitconfig:21, first reported in review #476) — The current .gitconfig sets smudge = cat for all three required filters, so initial checkout no longer invokes the not-yet-checked-out script. The installer subsequently configures local smudge commands using the copy under Git's common directory; the added fresh-clone test covers this flow but was not run during this review.Reviewed the candidate findings against the pinned head and the supplied base-to-head diff. Verification was limited to repository reads; no tests or Git commands were run.
Change walkthrough
.git-filters/obs-websocket-filter,.git-filters/opencode-api-keys,.gitattributes,.gitconfigREADME.mdscripts/dotfiles-secrets.py,scripts/test_dotfiles_secrets.pyReview effort: 3/5.
Static observations (not validation results)
Reviewed
214545ec8174fd65040ef1a18f0fe6e839558e92withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra. Automated advisory review; no project commands or tests were executed.@ -0,0 +180,4 @@expected_hooks = {name: '#!/bin/sh\n# dotfiles-secrets managed hook\nexec ' + command + ' check ' + name + '\n' for name in ('pre-commit', 'pre-push')}for name, expected in expected_hooks.items():path = hooks / nameif path.is_symlink() or path.exists() and path.read_text() != expected:[P2] Quality: Interpreter changes prevent reinstalling managed hooks
The installer embeds the current Python executable path in its hooks and requires existing hooks to match that exact text. Reinstalling with a different interpreter therefore refuses even though the existing hooks were installed by this tool.
Trigger: Install using a virtual-environment or version-managed Python, then remove or replace that interpreter and rerun the documented installer with another Python.
Impact: The hooks and required filters still reference the missing interpreter, blocking commits and filtered Git operations. The documented reinstall cannot repair them without manual intervention.
Evidence: scripts/dotfiles-secrets.py:179-180 builds hook commands from sys.executable; lines 181-184 reject any existing hook whose contents differ from the newly generated command. The local filter commands at lines 193-195 also embed that executable path, and the rejection occurs before they can be updated.
Review #477 interpreter-path instability confirmed. Managed commands now invoke python3 by stable command name rather than embedding a versioned sys.executable path, so distro/mise interpreter updates do not make unmodified managed hooks look customized. Six integration tests pass at
01efc68df7.Pi code review
2 new actionable findings
scripts/dotfiles-secrets.py:37scripts/dotfiles-secrets.py:125Earlier findings: 1 rechecked
scripts/dotfiles-secrets.py:183, first reported in review #477) — scripts/dotfiles-secrets.py:179 now constructs the command with literal python3, rather than sys.executable. The expected hooks and local filter configuration derive from that command, so reinstalling the current version with another interpreter does not change the expected hook text.Merged the candidate reviews of the filter, installer, hooks, configuration, and documentation against the supplied base and head. Review was static and read-only; tests and live Git operations were not run.
Change walkthrough
.git-filters/obs-websocket-filter,.git-filters/opencode-api-keys,.gitattributes,.gitconfigREADME.mdscripts/dotfiles-secrets.py,scripts/test_dotfiles_secrets.pyReview effort: 4/5.
Static observations (not validation results)
Reviewed
01efc68df7b1c27ee4a5ec9435dc6f1670f3b499withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra. Automated advisory review; no project commands or tests were executed.@ -0,0 +34,4 @@def state_dir() -> Path:# Independent of the checkout and XDG overrides: never accidentally stow secrets.directory = Path.home() / '.local/state/dotfiles-secrets'for part in [directory, *directory.parents]:[P2] Quality: System home-directory symlinks block installation and Git hooks
The private-state check rejects symlinks even in system-owned ancestors above the user's home. A conventional layout such as Fedora Silverblue's /home symlink therefore prevents the installer and all installed checks from using the store.
Trigger: Install or use the filters with HOME under a symlinked system directory, such as /home pointing to /var/home.
Impact: Installation fails, and an already installed setup blocks filtered Git operations, commits, and pushes until the layout or checks are changed.
Evidence: scripts/dotfiles-secrets.py:37 checks every parent of the state directory, including /home, and raises for any symlink. Both transform() and check() call state_dir(); install() calls transform() when capturing existing credential files.
@ -0,0 +122,4 @@def check_blob(path: str, data: bytes, known: list[bytes]) -> None:# JSON escaping must not hide a copied local credential in an unfiltered file.variants = [variant for secret in known for variant in (secret, json.dumps(secret.decode(), ensure_ascii=False)[1:-1].encode(), json.dumps(secret.decode(), ensure_ascii=True)[1:-1].encode())]if TOKEN.search(data) or any(secret in data for secret in variants):[P2] Quality: Short credentials can make unrelated content block commits
The hooks treat every stored credential as a substring that must be absent from every tracked blob. A valid local credential that also occurs in ordinary text thus causes false positives across the entire staged tree and outgoing history.
Trigger: Capture an OBS password such as "proxy", then commit a tree containing the tracked Pi settings, whose defaultProvider is "proxy".
Impact: Ordinary commits and pushes are rejected despite the credential field itself being sanitized, until the credential is changed or the checks are bypassed.
Evidence: scripts/dotfiles-secrets.py:139 loads all non-placeholder stored values, and lines 124–126 reject any blob containing one as a substring. check() scans every blob in the staged tree or outgoing commits; .pi/agent/settings.json contains "proxy" as a non-secret provider name.
Review #479 fixed in
01780bfff4: resolve the home root before checking only below-home private-state components, while still rejecting folded .local/state symlinks; limit whole-tree copied-secret substring detection to values >=12 bytes to avoid ordinary-text false positives from short passwords. Protected credential fields are sanitized/checked regardless of length. README explicitly documents the short-copy scanning limitation. Seven integration tests pass, including symlinked HOME and a short proxy password with unrelated proxy text.Pi code review
0 new actionable findings
No new actionable findings. Previously reported issues, if any, are tracked below.
Earlier findings: 2 rechecked
scripts/dotfiles-secrets.py:125, first reported in review #479) — check_blob now excludes credentials shorter than 12 bytes from substring matching, so the reported password 'proxy' no longer blocks ordinary text. The added short-password test covers this trigger.scripts/dotfiles-secrets.py:37, first reported in review #479) — state_dir resolves HOME before checking for symlinks in .local, .local/state, and the private store directory, so symlinked system ancestors above HOME are no longer rejected. An added test covers a symlinked HOME.Reviewed the filter, installer, hook, test, and documentation changes against the supplied base and head. Verification was static; no checks were run.
Change walkthrough
.git-filters/obs-websocket-filter,.git-filters/opencode-api-keys,.gitattributes,.gitconfigREADME.mdscripts/dotfiles-secrets.py,scripts/test_dotfiles_secrets.pyReview effort: 3/5.
Static observations (not validation results)
Reviewed
01780bfff459bf8f7f9966740ac9068d8e53479cwithproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-terra. Automated advisory review; no project commands or tests were executed.Installed on Witherbloom after clean exact-head review #480; merged as
bc1a900. Seven actual-Git integration tests pass on asmadi and Witherbloom. Required local filters and executable pre-commit/pre-push hooks active. Existing gt OAuth helper and post-checkout hook preserved. Private store directory0700/file0600; original ignored OBS backup migrated privately. Live OBS/OpenCode bytes unchanged by installation; published OBS blob has CHANGEME and smudge restoration verified without printing credentials.Published sanitized desktop recovery branch recovery/witherbloom/sanitized-desktop-20261105 at52f608161b50294ff291d85914aaa531b1caffd2 using a separate index; original index, HEAD and working-file hashes unchanged by snapshot/push. Includes machine-specific monitor/provider/OBS/gt settings; not merged into shared defaults. Real push passed the installed outgoing-history checks. Neocities pointers repaired with original file hashes unchanged; Orcus transcript locally ignored; throwaway shader untouched/untracked.