fix: address security concerns from PR review

- Add URL validation to download-attachment (only allow http/https)
- Add filename sanitization to prevent path traversal attacks
- Add timeouts to download commands (30 seconds)
- Add branch name sanitization in pull-request command
- Check for existing branches to avoid conflicts
- Add check for current feature branch

Addresses security concerns raised by Claude in PR #1 review
This commit is contained in:
Noah Brier
2025-09-14 17:15:52 -04:00
parent 48135c045f
commit 7b86627727
2 changed files with 28 additions and 6 deletions
+17 -5
View File
@@ -17,17 +17,29 @@ Download files from URLs to attachments folder and organize them with descriptiv
You are tasked with downloading files from URLs and organizing them in the Obsidian vault attachments folder. You are tasked with downloading files from URLs and organizing them in the Obsidian vault attachments folder.
### Step 1: Parse URLs ### Step 1: Parse and Validate URLs
Extract the URL(s) from the user's input. Handle multiple URLs if provided. Extract the URL(s) from the user's input. Handle multiple URLs if provided.
- **Validate URL scheme**: Only allow http:// or https:// URLs
- **Reject invalid URLs**: file://, ftp://, or malformed URLs
- **Example validation**:
```bash
if [[ ! "$url" =~ ^https?:// ]]; then
echo "Error: Only HTTP/HTTPS URLs are allowed"
exit 1
fi
```
### Step 2: Download Files ### Step 2: Download Files
For each URL: For each URL:
```bash ```bash
# Create temp filename based on URL # Sanitize filename to prevent path traversal
# Use wget or curl to download # Remove ../ and other dangerous characters
wget -O "05_Attachments/[filename]" "[url]" filename=$(basename "$url" | sed 's/[^a-zA-Z0-9._-]/_/g')
# Use wget or curl to download with timeout
wget --timeout=30 -O "05_Attachments/$filename" "$url"
# or # or
curl -L "[url]" -o "05_Attachments/[filename]" curl --max-time 30 -L "$url" -o "05_Attachments/$filename"
``` ```
### Step 3: Verify Downloads ### Step 3: Verify Downloads
+11 -1
View File
@@ -13,12 +13,22 @@ Automate the entire pull request workflow: create branch, stage changes, commit
- Check for uncommitted changes to include - Check for uncommitted changes to include
- Verify GitHub CLI (`gh`) is available - Verify GitHub CLI (`gh`) is available
- Get current branch as base branch - Get current branch as base branch
- If already on feature branch, ask: "Create PR from current branch?"
### 2. **Create Feature Branch** ### 2. **Create Feature Branch**
```bash ```bash
# Generate branch name from PR title or use provided name # Generate branch name from PR title or use provided name
# Sanitize branch name: lowercase, replace spaces with hyphens, remove special chars
branch_name=$(echo "$branch_name" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/--*/-/g')
# Check if branch already exists
if git show-ref --verify --quiet refs/heads/$branch_name; then
echo "Branch $branch_name already exists, using alternative name"
branch_name="${branch_name}-$(date +%s)"
fi
# Format: feature/short-description or fix/issue-name # Format: feature/short-description or fix/issue-name
git checkout -b feature/[branch-name] git checkout -b $branch_name
``` ```
### 3. **Stage and Review Changes** ### 3. **Stage and Review Changes**