diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 8cfef1b..0880885 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -1,3 +1,18 @@ +# Sentinel Journal + +## 2026-04-15 - Prevent TOCTOU in SSH Key Restoration + +**Vulnerability:** A Time-of-Check to Time-of-Use (TOCTOU) vulnerability where an +SSH private key is briefly world-readable upon creation before `chmod 600` is +applied. + +**Learning:** Redirecting output to a file creates the file with default +permissions (often `644`), which exposes sensitive data for a fraction of a +second. + +**Prevention:** Wrap commands that create sensitive files in a subshell using +`umask 077` to ensure the file is created with secure permissions (`600`) +natively. # Sentinel Security Journal ## 2026-04-16 - Prevent TOCTOU and Symlink Attacks via Insecure Temporary Directories diff --git a/tools/setup-ssh-keys.sh b/tools/setup-ssh-keys.sh index bde52fd..6ecd8db 100755 --- a/tools/setup-ssh-keys.sh +++ b/tools/setup-ssh-keys.sh @@ -153,7 +153,7 @@ cmd_restore() { chmod 700 "$SSH_DIR" # Read private key from 1Password and save locally - op read "op://$VAULT/$KEY_NAME/private_key" > "$PRIVATE_KEY_FILE" + (umask 077 && op read "op://$VAULT/$KEY_NAME/private_key" > "$PRIVATE_KEY_FILE") chmod 600 "$PRIVATE_KEY_FILE" # Read public key from 1Password and save locally