fix: close TOCTOU in LoadLocalSigner and LoadEVMSigner (PILOT-86)#3
Open
matthew-pilot wants to merge 1 commit into
Open
fix: close TOCTOU in LoadLocalSigner and LoadEVMSigner (PILOT-86)#3matthew-pilot wants to merge 1 commit into
matthew-pilot wants to merge 1 commit into
Conversation
Replace os.Stat + os.ReadFile with os.Open + fd.Stat + io.ReadAll to eliminate the time-of-check/time-of-use window where an attacker can chmod the identity file between the permission check and the read. pkg/wallet/signer.go LoadLocalSigner: os.Stat→fd.Stat on opened fd pkg/evm/key.go LoadEVMSigner: same pattern All three operations (stat, validate, read) now target the same inode handle — the fd guarantees identity of the checked file. Tests: 5/5 packages pass (go test ./...) Vet: clean
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
What
Closes a time-of-check/time-of-use (TOCTOU) race in two identity-loading functions:
pkg/wallet/signer.goLoadLocalSigner(Ed25519 key)pkg/evm/key.goLoadEVMSigner(secp256k1 key)Both used
os.Stat(path)to validate 0600 permissions, thenos.ReadFile(path)to load the key material. An attacker with local filesystem access couldchmod 0644between the two syscalls, defeating the permission check entirely.Fix
Replace the two-step path-based check with a single fd-based operation:
All three operations (open, stat, read) now target the same inode via the file descriptor — the kernel guarantees identity of the underlying file.
Verification
Jira
PILOT-86 — Wallet TOCTOU on private-key file permission check