* feat: Add image diff display support for inline and side-by-side layouts - Add image file detection utility in imageUtils.ts - Implement ImageDiffChunk component with before/after image display - Support both inline (vertical) and side-by-side (horizontal) layouts - Add /api/blob/* endpoint for serving image files from git refs - Update GitDiffParser to handle binary files and serve blob content - Integrate image diff display in DiffViewer component - Handle deleted, added, and modified image files appropriately 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * 画像の表示 * added/deleted対応 * 背景透過対応 * サイズの表記を追加 * 表示位置修正 * ファイルサイズ上限設定10MB * staged/.対応 * create tests * Fix command injection vulnerability in getBlobContent 依頼されたプロンプト内容: execやexecSyncなど任意コード実行のところで、自由な入力を実行しているなど危険な実装がないかレビューしてほしい 実行したTODOリスト: 1. getBlobContent関数のセキュリティ問題を修正 2. 修正後のテストを実行 3. lint/typecheckを実行 Changes: - Replace execSync with execFileSync to prevent command injection - Update tests to use execFileSync mock instead of execSync - Remove unused mockExecSync variable 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update SECURITY_ANALYSIS.md to reflect execFileSync fix - Mark command injection vulnerability as FIXED - Update code examples to show execFileSync usage - Update risk assessment from MEDIUM to LOW - Document completed security improvements * update document name --------- Co-authored-by: Claude <noreply@anthropic.com>
5.0 KiB
Security Analysis Report - Code Execution Patterns
Summary
I've analyzed the codebase for potentially dangerous code execution patterns. Overall, the code appears to follow secure practices with proper input validation and sanitization. Here are the findings:
Code Execution Patterns Found
1. execSync Usage (src/cli/utils.ts)
Location: Lines 93-94, 138-145
// Getting GitHub token
const result = execSync('gh auth token', { encoding: 'utf8', stdio: 'pipe' });
// Verifying commit existence
execSync(`git cat-file -e ${sha}`, { stdio: 'ignore' });
execSync('git fetch origin', { stdio: 'ignore' });
Security Assessment: LOW RISK
- The
shaparameter is validated before use - Commands are using fixed patterns with minimal user input
- The SHA is already verified to exist in the git repository
2. execFileSync Usage (src/server/git-diff.ts) - FIXED
Location: Lines 224-241
// Handle staged files
const buffer = execFileSync('git', ['show', `:${filepath}`], {
maxBuffer: 10 * 1024 * 1024, // 10MB limit
});
// Get blob hash
const blobHash = execFileSync('git', ['rev-parse', `${ref}:${filepath}`], {
encoding: 'utf8',
maxBuffer: 10 * 1024 * 1024,
}).trim();
// Get raw binary content
const buffer = execFileSync('git', ['cat-file', 'blob', blobHash], {
maxBuffer: 10 * 1024 * 1024, // 10MB limit
});
Security Assessment: LOW RISK (Previously MEDIUM RISK)
- FIXED: Changed from
execSynctoexecFileSyncto prevent command injection - Arguments are now passed as an array, preventing shell interpretation
- The
filepathandrefparameters are safely passed without shell expansion - Resource limits (10MB) remain in place to prevent exhaustion attacks
- No shell metacharacter interpretation occurs with
execFileSync
3. spawn Usage (scripts/dev.js)
Location: Lines 10-14, 29-32
const cliProcess = spawn('pnpm', ['run', 'dev:cli', commitish, '--no-open'], {
stdio: ['inherit', 'pipe', 'inherit'],
shell: true,
});
viteProcess = spawn('vite', ['--open'], {
stdio: 'inherit',
shell: true,
});
Security Assessment: LOW RISK
- This is a development script, not production code
- The
commitishparameter comes from command line but is passed as an array element, not interpolated
4. child_process Import (src/server/git-diff.ts)
Location: Line 224
const { execFileSync } = await import('child_process');
Security Assessment: EXPECTED
- Dynamic import is used but the module name is hardcoded
- This is the standard Node.js module for executing commands
- Now imports
execFileSyncinstead ofexecSyncfor better security
Input Validation Analysis
Positive Findings:
-
Commit-ish Validation (src/cli/utils.ts)
- Comprehensive validation function
validateCommitish()that checks input against safe patterns - Rejects potentially dangerous inputs like empty strings or
HEAD~ - Uses regex patterns to validate SHA hashes, branch names, and special references
- Comprehensive validation function
-
GitHub PR URL Validation (src/cli/utils.ts)
parseGitHubPrUrl()properly validates URL format- Ensures hostname is github.com
- Validates pull request number is numeric
-
Diff Arguments Validation (src/cli/utils.ts)
validateDiffArguments()ensures proper argument combinations- Prevents comparing same values
- Restricts special arguments to specific positions
-
Express Route Parameters
- File paths in
/api/blob/endpoint are captured but used within git commands that have their own validation
- File paths in
Recommendations
✅ Completed:
- [FIXED] Command injection vulnerability in
getBlobContent():- Changed from
execSynctoexecFileSync - Arguments are now safely passed as an array
- Shell metacharacter injection is no longer possible
- Changed from
Medium Priority:
- Consider using git library methods instead of direct command execution where possible
- Add explicit validation for the
refparameter ingetBlobContent()as an additional defense layer
Low Priority:
- Document security considerations for developers about input validation requirements
- Consider adding rate limiting to prevent resource exhaustion attacks
Conclusion
The codebase demonstrates good security practices with proper input validation. The previously identified command injection vulnerability in getBlobContent() has been fixed by switching from execSync to execFileSync. The remaining risks are low because:
- The application is designed to run locally, not as a public web service
- Most user inputs go through validation functions
- The commands executed are limited to git operations within the repository context
- Resource limits are in place (10MB file size limit)
- [FIXED] Shell command injection is no longer possible with the use of
execFileSync
The code does not use dangerous patterns like eval(), Function() constructor, or dynamic require() with user input.