-
Notifications
You must be signed in to change notification settings - Fork 1
π‘οΈ Sentinel: [HIGH] Fix TOCTOU vulnerability in SSH key creation #31
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ## 2024-05-22 - SSH Key TOCTOU Vulnerability | ||
|
Check failure on line 1 in .jules/sentinel.md
|
||
| **Vulnerability:** SSH private keys were created with default permissions (likely 644/664) and then chmod'ed to 600, creating a Time-of-Check Time-of-Use (TOCTOU) race condition where the key was briefly world-readable. | ||
|
Check failure on line 2 in .jules/sentinel.md
|
||
| **Learning:** Shell redirection (`>`) creates files with default umask permissions before any subsequent `chmod` command can run. | ||
|
Check failure on line 3 in .jules/sentinel.md
|
||
| **Prevention:** Use `(umask 077 && command > file)` in a subshell to ensure the file is created with restrictive permissions (600) from the very beginning. | ||
|
Check failure on line 4 in .jules/sentinel.md
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Create a temporary directory for the test environment | ||
| TEST_HOME=$(mktemp -d) | ||
| trap 'rm -rf "$TEST_HOME"' EXIT | ||
|
|
||
| # Export HOME to point to the temporary directory | ||
| export HOME="$TEST_HOME" | ||
|
|
||
| # Also set XDG vars to use temp dir (for safety) | ||
| export XDG_CONFIG_HOME="$TEST_HOME/.config" | ||
| export XDG_DATA_HOME="$TEST_HOME/.local/share" | ||
| export XDG_STATE_HOME="$TEST_HOME/.local/state" | ||
|
|
||
| # Setup mock op | ||
| mkdir -p "$TEST_HOME/bin" | ||
| cat > "$TEST_HOME/bin/op" <<'EOF' | ||
| #!/bin/bash | ||
| if [[ "$1" == "account" && "$2" == "list" ]]; then | ||
| echo "fake-account" | ||
| exit 0 | ||
| fi | ||
| if [[ "$1" == "item" && "$2" == "get" ]]; then | ||
| exit 0 | ||
| fi | ||
| if [[ "$1" == "read" ]]; then | ||
| echo "fake-key-content" | ||
| exit 0 | ||
| fi | ||
| EOF | ||
| chmod +x "$TEST_HOME/bin/op" | ||
| export PATH="$TEST_HOME/bin:$PATH" | ||
|
|
||
| # Setup config | ||
| mkdir -p "$XDG_CONFIG_HOME/dotfiles" | ||
| echo "ssh:" > "$XDG_CONFIG_HOME/dotfiles/config.yaml" | ||
| echo " vault: test-vault" >> "$XDG_CONFIG_HOME/dotfiles/config.yaml" | ||
| echo " item_name: test-key" >> "$XDG_CONFIG_HOME/dotfiles/config.yaml" | ||
|
|
||
| # Run restore | ||
| # We run the script from the repo root | ||
| ./tools/setup-ssh-keys.sh restore | ||
|
|
||
| # Verify file exists in the fake home | ||
| if [[ -f "$HOME/.ssh/id_ed25519" ]]; then | ||
| echo "Key restored successfully to $HOME/.ssh/id_ed25519" | ||
| else | ||
| echo "Key restore failed" | ||
| exit 1 | ||
| fi | ||
|
Comment on lines
+46
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test doesn't verify file permissions β the core assertion for this fix is missing. The entire PR is about ensuring the private key is created with Proposed fix # Verify file exists in the fake home
if [[ -f "$HOME/.ssh/id_ed25519" ]]; then
echo "Key restored successfully to $HOME/.ssh/id_ed25519"
+ # Verify permissions are 600 (the whole point of the TOCTOU fix)
+ PERMS=$(stat -c '%a' "$HOME/.ssh/id_ed25519" 2>/dev/null || stat -f '%Lp' "$HOME/.ssh/id_ed25519")
+ if [[ "$PERMS" != "600" ]]; then
+ echo "FAIL: Expected permissions 600, got $PERMS"
+ exit 1
+ fi
+ echo "Permissions verified: $PERMS"
else
echo "Key restore failed"
exit 1
fiπ€ Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix markdown lint violations flagged by CI.
The
Lint Documentationcheck is failing with multiple issues:#instead of##).Proposed fix
π Committable suggestion
π§° Tools
πͺ GitHub Check: Lint Documentation
[failure] 4-4: Line length
.jules/sentinel.md:4:81 MD013/line-length Line length [Expected: 80; Actual: 155] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md013.md
[failure] 3-3: Line length
.jules/sentinel.md:3:81 MD013/line-length Line length [Expected: 80; Actual: 129] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md013.md
[failure] 2-2: Line length
.jules/sentinel.md:2:81 MD013/line-length Line length [Expected: 80; Actual: 219] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md013.md
[failure] 1-1: First line in a file should be a top-level heading
.jules/sentinel.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## 2024-05-22 - SSH Key TOCTOU..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md041.md
[failure] 1-1: Headings should be surrounded by blank lines
.jules/sentinel.md:1 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## 2024-05-22 - SSH Key TOCTOU Vulnerability"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md022.md
π€ Prompt for AI Agents