-
Notifications
You must be signed in to change notification settings - Fork 1
π‘οΈ Sentinel: [MEDIUM] Fix insecure file permissions in backup script #38
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 @@ | ||
| ## 2026-02-22 - Insecure Default Permissions on Backups | ||
|
Check failure on line 1 in .jules/sentinel.md
|
||
| **Vulnerability:** The `tools/backup-projects.sh` script created zip archives with default permissions (often `644` or `664`), allowing other users on the system to read potentially sensitive project backups. | ||
|
Check failure on line 2 in .jules/sentinel.md
|
||
| **Learning:** Shell scripts using tools like `zip` or `tar` do not automatically restrict permissions of the output file unless `umask` is set. | ||
|
Check failure on line 3 in .jules/sentinel.md
|
||
| **Prevention:** Always set `umask 077` at the beginning of shell scripts that generate sensitive files or directories to ensure they are private by default. | ||
|
Check failure on line 4 in .jules/sentinel.md
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+2
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. Add Without strict mode, a failing intermediate command (e.g., β»οΈ Proposed fix #!/bin/bash
+set -euo pipefail
+
# Setup test environmentπ€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| # Setup test environment | ||||||||||||||||||||||||||||||||||||
| PROJECT_DIR="$HOME/kidchenko" | ||||||||||||||||||||||||||||||||||||
| BACKUP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/dotfiles/backups" | ||||||||||||||||||||||||||||||||||||
| BACKUP_DIR="${BACKUP_DIR/#\~/$HOME}" # Expand ~ just in case | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Create dummy project | ||||||||||||||||||||||||||||||||||||
| mkdir -p "$PROJECT_DIR" | ||||||||||||||||||||||||||||||||||||
| echo "secret content" > "$PROJECT_DIR/secret.txt" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Ensure cleanup | ||||||||||||||||||||||||||||||||||||
| trap 'rm -rf "$PROJECT_DIR"' EXIT | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+13
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.
Fix: check whether the directory pre-existed and only delete it if this test created it. π‘οΈ Proposed fix-# Create dummy project
-mkdir -p "$PROJECT_DIR"
-echo "secret content" > "$PROJECT_DIR/secret.txt"
-
-# Ensure cleanup
-trap 'rm -rf "$PROJECT_DIR"' EXIT
+# Create dummy project β track pre-existence to avoid destroying real data
+_project_dir_existed=false
+[[ -d "$PROJECT_DIR" ]] && _project_dir_existed=true
+mkdir -p "$PROJECT_DIR"
+echo "secret content" > "$PROJECT_DIR/secret.txt"
+
+# Cleanup: only remove the directory wholesale if this test created it
+_cleanup() {
+ rm -f "$PROJECT_DIR/secret.txt"
+ [[ "$_project_dir_existed" == false ]] && rm -rf "$PROJECT_DIR"
+}
+trap _cleanup EXITπ Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Run backup script | ||||||||||||||||||||||||||||||||||||
| # It reads default folders which includes ~/kidchenko | ||||||||||||||||||||||||||||||||||||
| echo "Running backup script..." | ||||||||||||||||||||||||||||||||||||
| # Using --verbose to see output, but suppressing standard output unless needed | ||||||||||||||||||||||||||||||||||||
| if ! bash tools/backup-projects.sh backup --verbose > /tmp/backup_output.log 2>&1; then | ||||||||||||||||||||||||||||||||||||
| echo "Backup failed. Output:" | ||||||||||||||||||||||||||||||||||||
| cat /tmp/backup_output.log | ||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Find the latest backup | ||||||||||||||||||||||||||||||||||||
| LATEST_BACKUP=$(ls -t "$BACKUP_DIR"/project-backup-*.zip 2>/dev/null | head -n1) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if [[ -z "$LATEST_BACKUP" ]]; then | ||||||||||||||||||||||||||||||||||||
| echo "Error: No backup file created in $BACKUP_DIR" | ||||||||||||||||||||||||||||||||||||
| cat /tmp/backup_output.log | ||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| echo "Backup created: $LATEST_BACKUP" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Check permissions | ||||||||||||||||||||||||||||||||||||
| if [[ "$OSTYPE" == "darwin"* ]]; then | ||||||||||||||||||||||||||||||||||||
| PERMS=$(stat -f %Lp "$LATEST_BACKUP") | ||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||
| PERMS=$(stat -c %a "$LATEST_BACKUP") | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| echo "Permissions: $PERMS" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Cleanup backup file | ||||||||||||||||||||||||||||||||||||
| rm -f "$LATEST_BACKUP" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # We expect 600 (rw-------) | ||||||||||||||||||||||||||||||||||||
| if [[ "$PERMS" != "600" ]]; then | ||||||||||||||||||||||||||||||||||||
| echo "FAILURE: Permissions are too open ($PERMS). Expected 600." | ||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||
| echo "SUCCESS: Permissions are correct (600)." | ||||||||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
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 failures blocking the CI "Lint Documentation" check.
Five violations are reported:
#heading, not##.π 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: 156] 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: 143] 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: 208] 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: "## 2026-02-22 - Insecure Defau..."] 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: "## 2026-02-22 - Insecure Default Permissions on Backups"] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md022.md
π€ Prompt for AI Agents