Repository navigation
Fix open issues from the 2026-09-30 b58fce9 reanalysis (4.1-4.4) - #13
Merged
Merged
Conversation
The 2026-09-30 reanalysis (finding 4.2) found that LooksEncrypted validated each ENC[...] field independently instead of sharing Parse's grammar, so a plaintext value shaped like one of these was wrongly treated as already-encrypted and left unprotected by Clean: ENC[AES256_SIV,data:] ENC[AES256_SIV,data:AAAA,data:AAAA] ENC[AES256_SIV_TB,data:AAAA] LooksEncrypted now delegates to the same positional field-parsing core Parse uses (rejecting duplicate/reordered/trailing fields and an AES256_SIV_TB tag missing its mandatory key field automatically), with one documented, narrow exception: a keyless pre-rotation AES256_SIV tag is still recognized as genuine ciphertext rather than double-wrapped. It also now rejects a "data:" field that decodes to fewer bytes than real AES-256-SIV output can ever be (internal/siv.MinCiphertextLen). Several existing test fixtures used placeholder ciphertext shorter than that minimum; bumped them to realistic lengths rather than loosening the new check to keep them passing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The 2026-09-30 reanalysis (finding 4.4) found that validTypeLiteral used strconv's own parsers to decide whether a decrypted value was a genuine literal of its claimed type, but strconv is more permissive than either output format: strconv.ParseFloat accepts "NaN"/"Inf", and strconv.ParseBool accepts "1"/"t" and more. Neither reads back as the claimed type in JSON or this project's YAML handling, so an attacker with write access who flips a legacy (pre-Package-F, unauthenticated) tag's type field onto one of these could make Clean/Smudge render invalid JSON, or a silently wrong-typed value. Added Handler.RoundTrip (internal/format): it renders a value as its claimed type, then re-reads that rendered text back through the same Locate function Clean/Smudge already use, requiring the exact same value and type to come back out. validTypeLiteral now uses this for TypeFloat/TypeBool instead of strconv directly. TypeInt keeps its existing strconv range check, since JSON has no defined integer range for RoundTrip to enforce on its own (the deliberate int64-overflow limit from the original R06 fix). Because Render and Locate are the same pair of functions a field's type was originally classified by, anything that actually went through Clean normally round-trips by construction — this only ever rejects a value whose claimed type doesn't match what a parser would otherwise infer for it, i.e. exactly the adversarial case. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The 2026-09-30 reanalysis (finding 4.3) found that Set's read-modify-write of the local key file was serialized only within one process (setMu): two concurrent `nebel` processes (a racing filter invocation, two concurrent `nebel rotate` runs, ...) could each read the same old content and then each write back a different, equally "complete" update, silently losing whichever lost the race. A corrected repro (the originally reported figure was a test-isolation artifact, not a real measurement) lost 37 of 60 concurrent registrations in a single run. Set now also takes an exclusive, cross-process advisory lock on a dedicated sibling file for the same read-modify-write span: flock on Unix (internal/localkey/filelock_unix.go), LockFileEx on Windows (filelock_windows.go). Locking a sibling file rather than the key file itself matters because writeKeyFile replaces the key file by renaming a temp file onto it (for atomicity against a concurrent reader) — a lock held on the key file's own inode would stop protecting anything the moment the first writer's rename swapped a new inode in underneath it. Also adds: - Remove, to delete a single version's entry (used by cmd/nebel/rotate.go in a later commit to undo its own Set on a failed, reverted rotation). - LockRotation, a second lock serializing an entire `nebel rotate` operation against another concurrent one in the same clone (used in the same later commit) — Set's own lock only protects the key file's bytes, not the higher-level decision of which next version number to mint, so it alone doesn't stop two concurrent rotations from both reading the same current version and each minting the same next one with a different key. golang.org/x/sys was already an indirect dependency (via golang.org/x/term); go.mod now lists it directly, with no version change. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…races
The 2026-09-30 reanalysis (finding 4.1) found that rotateRecoveryHint told
the user to run `git checkout -- .` to undo a failed rotation, claiming it
"fully discards" the attempt. That command restores the working tree from
the index, not HEAD — once gitutil.Add had already staged the rotated
config (exactly the state when a later re-encryption failure is reported),
the rotation stayed staged afterward despite the message's claim. `.`
could also discard unrelated uncommitted work elsewhere in the repo.
`nebel rotate` now reverts itself automatically instead of printing
instructions. Before changing anything, it snapshots .nebel.yaml's exact
working-tree bytes and index entry ("<mode>,<sha>", gitutil.IndexEntry),
and the local keyring's prior entry (if any) for the version it's about
to mint. On any failure, it restores all of that precisely:
- The working tree file, always.
- The index entry via gitutil.SetIndexEntry rather than re-running `git
add` — which would instead stage whatever happens to be in the working
tree by then, including a pre-existing unstaged edit to .nebel.yaml that
predates this rotate attempt and was never staged in the first place.
- The local key registration for the version this attempt minted: Set it
back to whatever was there before (almost always nothing, so Remove),
rather than leaving this attempt's orphaned key registered. Left behind,
it would collide with whatever key a teammate's own later, independent
rotation to that same version number eventually registers, turning that
clone's next `git pull` into a hard authentication failure instead of
the usual graceful "missing key" passthrough.
Restoring to the snapshot taken when this attempt started, not to HEAD,
matters: AC-11.9 explicitly allows running `rotate` again before a
previous rotation is even committed, in which case HEAD is one rotation
further back than what a failed retry should revert to.
Also closes the other half of reanalysis finding 4.3: two concurrent
`nebel rotate` runs in the same clone could each read the same current
version and independently mint the same next one with a different key,
silently colliding. runRotate now holds localkey.LockRotation for the
whole operation, so the second attempt sees the first's committed-to-disk
result and mints the version after it instead.
Fixed the CLI help text, which claimed rotate "does not touch
already-encrypted content" — it eagerly re-encrypts everything.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The previous commit closed reanalysis finding 4.4 for floats and bools, but left ints on strconv.ParseInt alone. That accepts a leading "+" and leading zeros: "+5" isn't valid JSON number syntax, and "007" is neither valid JSON nor read back as an int by the YAML handler. A legacy value tag whose unauthenticated type field is flipped from str to int could therefore still render invalid JSON, or a silently changed type. validTypeLiteral now runs handler.RoundTrip for ints too. The strconv check stays alongside it for the deliberate int64 range limit, which RoundTrip can't enforce on its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the four open findings from
audits/2026-09-30-reanalysis-b58fce9.md, each confirmed with a real reproduction before fixing (not just the report's description taken at face value) and each covered by a regression test that was verified to actually fail on the pre-fix code.LooksEncryptedvalidated eachENC[...]field independently instead of sharingParse's grammar, so several malformed-but-prefix-matching strings (e.g.ENC[AES256_SIV,data:]) were wrongly treated as already-encrypted and left unprotected byClean.git checkout -- ., which doesn't do what it claimed once the config was already staged.rotatenow reverts itself automatically (config file, index entry, and orphaned local key) instead of printing instructions, and the auto-revert knows the difference between a plainHEADand a still-uncommitted prior rotation (AC-11.9).Set's read-modify-write of the local key file had no cross-process locking; a corrected repro lost 37/60 concurrent registrations in one run (the report's own repro number turned out to be a test-isolation artifact — corrected here). Added flock/LockFileEx-based locking, plus a second lock closing the related "two concurrent rotates mint the same version" collision the original report also described.validTypeLiteralusedstrconv's parsers, which are more permissive than either output format (NaN/Inffor floats,1/tfor bools,+5/007for ints) — closed via a round-trip check against each format's ownLocate/Render. The int case was added in a follow-up commit after review.Commits
Five commits: one per finding, plus a follow-up closing 4.4's int case (
4.3's rotate-level half lives in the 4.1 commit since it's inseparable fromrotate.go's changes there — noted in that commit's message). Each commit was individually checked out into a throwaway worktree and built +go vet+ full test suite run against it in isolation to confirm it doesn't depend on a later commit.Test plan
go build ./...,go vet ./...(linux/amd64, linux/arm64, darwin/arm64, windows/amd64)go test ./...andgo test -race ./..., full suite, greenSetIndexEntryreverted toAdd, etc.) before being confirmed to pass against the fixscripts/gen-notices.shre-run — no diff (x/sys was already fully documented as an indirect dependency)Known remaining items (not in this PR)
nebel status(missing feature, spec 09)config.Saveis not atomic (a crash mid-write could still truncate.nebel.yaml, independent of this PR's revert logic)scanUndecrypted(used byrotate's pre-flight check) still uses the bareENC[prefix check rather than the now-stricterLooksEncrypted— a plaintext secret that happens to look like a malformed tag will now be correctly encrypted byClean, butrotatewould still misreport it as "stuck ciphertext" first run🤖 Generated with Claude Code