Commit Graph

27 Commits

Author SHA1 Message Date
Kazuki Yamada
3a10a9f255 fix(core): Use proper hostname validation for Azure DevOps URLs
Replace substring matching with proper URL parsing to fix CodeQL security alert.

Previously, the code used `includes()` for substring matching which could
incorrectly identify malicious URLs like `https://evil.com/dev.azure.com/`
as Azure DevOps URLs.

Changes:
- Extract Azure DevOps URL detection into a dedicated function
- Use URL constructor to parse and validate the hostname
- For SSH URLs, use `startsWith()` for exact prefix matching
- For HTTP(S) URLs, check the hostname property exactly
- Add security tests to ensure malicious URLs are not incorrectly identified

This resolves the "Incomplete URL substring sanitization" alert from CodeQL.
2025-10-07 23:43:38 +09:00
Kazuki Yamada
179ca6fba4 fix(core): Improve Azure DevOps URL parsing support
Address PR review feedback by expanding Azure DevOps URL support:

- Add support for SSH URLs (ssh.dev.azure.com)
- Add support for legacy Visual Studio Team Services (*.visualstudio.com)
- Remove invalid azure.com case
- Add test coverage for legacy VSTS URLs
- Move Azure DevOps detection before git-url-parse to avoid parsing issues

This ensures compatibility with all Azure DevOps URL formats including modern and legacy domains.
2025-10-07 23:28:36 +09:00
Kazuki Yamada
a2edd58e60 feat(core): Add support for Azure DevOps remote repository URLs
This commit adds support for Azure DevOps repository URLs in both SSH and HTTPS formats.

Azure DevOps uses a special URL structure that differs from standard Git hosting services:
- SSH: git@ssh.dev.azure.com:v3/organization/project/repo
- HTTPS: https://dev.azure.com/organization/project/_git/repo

The git-url-parse library can parse these URLs but its toString() method doesn't preserve
the full path structure (e.g., v3/organization/ part is lost in SSH URLs). To address this,
we now detect Azure DevOps URLs by checking the source field and use the original URL
as-is instead of reconstructing it.

Changes:
- Modified parseRemoteValue() to use switch statement for source-based URL handling
- Added Azure DevOps cases ('dev.azure.com' and 'azure.com') to preserve original URLs
- Added test cases for both Azure DevOps SSH and HTTPS URL formats
- All existing tests continue to pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-07 23:05:36 +09:00
Kazuki Yamada
ea1cc485c2 chore(config): disable organizeImports for src/index.ts
Added override configuration to disable Biome's organizeImports feature
specifically for src/index.ts to allow manual import order management
while keeping automatic import organization enabled for other files.
2025-09-21 13:54:12 +09:00
Kazuki Yamada
d5c5cd8bdc test(git): Update gitHubArchive test to use HEAD instead of main
Update the test expectation to reflect the change from hardcoded 'main'
branch to using HEAD for the repository's default branch.
2025-08-26 01:01:01 +09:00
Kazuki Yamada
bea8df18bb feat(git): Use HEAD instead of hardcoded main branch for GitHub archives
Replace hardcoded 'main' branch with 'HEAD' to automatically use the repository's default branch, eliminating issues with repositories that use different default branch names like 'master' or custom branches.

Changes:
- buildGitHubArchiveUrl now uses HEAD.zip instead of refs/heads/main.zip
- getArchiveFilename defaults to HEAD instead of main
- Updated corresponding tests to reflect the new behavior
2025-08-26 01:01:01 +09:00
Kazuki Yamada
1175bfb822 refactor(security): Extract duplicate warning logic into helper function
Extract logSuspiciousContentWarning helper function to eliminate code duplication
between Git diffs and Git logs security warning logic in validateFileSafety.ts.

This addresses PR feedback about duplicate code patterns and improves maintainability
by following DRY principles.
2025-08-23 13:30:19 +09:00
Kazuki Yamada
96da6c6045 fix(git): Resolve null character handling in git log command execution
Address Node.js execFileAsync limitation where null bytes in command arguments
cause execution to fail. Implement proper separation between Git format strings
and JavaScript parsing logic.

Changes:
- Separate Git format separator (%x00) from JavaScript parsing separator (\x00)
- Add GIT_LOG_FORMAT_SEPARATOR constant for Git command formatting
- Maintain GIT_LOG_RECORD_SEPARATOR for JavaScript string parsing
- Add comprehensive test coverage for git log functionality
- Support cross-platform line endings (CRLF/LF) in git log parsing
- Add gitLogHandle.test.ts with 13 test cases covering various scenarios

This resolves the "string without null bytes" error while maintaining
flexibility for custom separators and ensuring robust git log processing
across different platforms and git configurations.
2025-08-23 12:53:12 +09:00
Kazuki Yamada
e5d5349d72 test(git): Update test expectations for git command security improvements
Updated git command tests to expect the new `--` separators that were added
for security to prevent argument injection attacks. The tests now properly
validate the enhanced command arguments in execGitShallowClone and execLsRemote.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-14 23:32:18 +09:00
Kazuki Yamada
9708e1cf38 perf(test): Optimize gitHubArchive test execution time
Reduced test execution time from ~23s to ~3.5s (85% improvement) by:

- Reduced retry counts from 3 to 1-2 for error handling tests
- Shortened timeout values (100ms → 50ms) for timeout tests
- Removed unnecessary imports (createWriteStream, fs, Readable, pipeline)
- Fixed unused parameter warnings with underscore prefix (_data)

Performance improvements:
- "should retry on failure": 3005ms → 1002ms
- "should throw error after all retries fail": 2007ms → 2005ms (minor)
- "should handle ZIP extraction error": 6011ms → 3ms
- "should handle timeout": 408ms → 208ms
- Other error tests: 6000ms+ → 1-3ms each

The tests still validate all critical functionality including:
 Retry logic and exponential backoff behavior
 Error handling for network/ZIP failures
 Security protections and edge cases
 Timeout handling mechanisms

Trade-off: Slightly reduced retry testing depth for much faster CI/development cycles.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 00:20:43 +09:00
Kazuki Yamada
f4f911e637 test(git): Add comprehensive test suite for gitHubArchive.ts
Created thorough unit tests covering all functionality of the GitHub archive
download and extraction module. Tests include:

- Successful download and extraction flow
- Progress callback handling
- Retry logic with exponential backoff
- URL fallback strategies (main → master → tag)
- Error handling for network failures, ZIP corruption, timeouts
- Security validations for path traversal and absolute paths
- Archive cleanup on both success and failure
- Multiple response scenarios (404, timeout, missing body)

Test coverage includes:
- downloadGitHubArchive function with various scenarios
- isArchiveDownloadSupported function
- All edge cases and error conditions
- Security protection mechanisms

Uses proper mocking with vitest for external dependencies:
- fetch API for HTTP requests
- fflate library for ZIP extraction
- Node.js fs operations
- Stream processing components

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 00:15:10 +09:00
Kazuki Yamada
9e81c8926d security(git): Fix URL substring sanitization vulnerability
User reported security issue with incomplete URL validation:
- `remoteValue.includes('github.com')` could match malicious URLs like 'https://evil.com/github.com/user/repo'
- Replaced substring check with proper hostname validation using URL.hostname
- Added allowlist of legitimate GitHub hosts: ['github.com', 'www.github.com']
- Added comprehensive test cases to verify malicious URLs are rejected
- Ensures only legitimate GitHub domains are processed for archive download

This prevents URL spoofing attacks where arbitrary hosts could be treated as GitHub repositories.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-15 21:31:52 +09:00
Kazuki Yamada
8696b32db4 fix(github): Address PR review feedback for archive download feature
User requested fixes for GitHub archive download implementation based on PR review comments:
- Fix ref assignment to use nullish coalescing (??) instead of logical OR for proper empty string handling
- Add comprehensive test coverage for archive download path and git clone fallback scenarios
- Implement main/master branch fallback strategy to handle repositories with different default branches
- Enhance test assertions to verify fallback execution in remoteAction tests
- Add buildGitHubMasterArchiveUrl function with corresponding test coverage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-15 21:28:35 +09:00
Kazuki Yamada
5270bbcafe refactor(remote): Use fflate for ZIP extraction and improve GitHub URL parsing
User requested performance and reliability improvements:
- User asked: "zipの展開はfflateを使ってください"
- User asked: "gitのURLのパースは @src/core/git/gitRemoteParse.ts を参考にするか利用"
- User asked: "githubモジュールではなくgitフォルダに入れてください"

Key improvements:
- Replace system unzip dependency with fflate for cross-platform compatibility
- Move GitHub modules from core/github/ to core/git/ for better organization
- Consolidate GitHub URL parsing with existing git-url-parse functionality
- Fix branch name parsing for complex branch names like feature/test
- Improve URL parsing to handle slash-separated branch names correctly

Technical changes:
- Added fflate dependency for ZIP extraction
- Moved and renamed files: githubApi.ts -> gitHubArchiveApi.ts, githubArchive.ts -> gitHubArchive.ts
- Enhanced parseGitHubRepoInfo() to extract branches directly from URLs
- Updated all imports and test files for new structure
- All 661 tests passing with improved reliability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-15 20:47:16 +09:00
Kazuki Yamada
2914ce5e0e feat(remote): Implement GitHub archive download with git clone fallback
User requested performance optimization for remote repository processing:
- User asked: "archive zipをダウンロードしてくれば良い気もしています"
- User wanted: Archive download as primary method with git clone fallback
- User specified: Keep "cloning" display message for consistency

Implementation provides ~70% performance improvement for GitHub repositories
by downloading archive zip instead of full git clone when possible.

Key features:
- GitHub repository auto-detection from various URL formats
- Archive download priority with real-time progress tracking
- Seamless git clone fallback on archive download failure
- Comprehensive error handling with retry logic
- Support for branches, tags, and commit-specific downloads

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-15 20:13:23 +09:00
Kazuki Yamada
fecebc2ca6 refactor(core): Update GitDiffResult imports and restructure git handling modules 2025-05-24 14:14:26 +09:00
Kazuki Yamada
b13a21aebd refactor(core): Migrate GitDiffResult and related functions to gitHandle module 2025-05-24 13:59:32 +09:00
Kazuki Yamada
9f4d1bc462 refactor(core): Rename getRemoteRefs to execLsRemote and update implementation 2025-05-24 13:51:15 +09:00
Kazuki Yamada
0be489dcbb refactor(core): Update git command imports and restructure gitHandle module 2025-05-24 13:37:57 +09:00
Kazuki Yamada
081732f112 refactor(core): Rename getFileChangeCount to execGitLogFilenames and update return type 2025-05-24 13:24:43 +09:00
Devin AI
58495bc584 style: Fix formatting in gitCommand.test.ts
Co-Authored-By: Kazuki Yamada <koukun0120@gmail.com>
2025-05-24 02:40:50 +00:00
Devin AI
3dda598def refactor: Improve error message for invalid URL protocol
Co-Authored-By: Kazuki Yamada <koukun0120@gmail.com>
2025-05-24 02:37:26 +00:00
Devin AI
9c4e77333f style: Fix linting issues in gitCommand.test.ts
Co-Authored-By: Kazuki Yamada <koukun0120@gmail.com>
2025-05-24 11:34:56 +09:00
Devin AI
2f4f84209d fix(core): Throw errors for invalid URLs in getRemoteRefs function
Co-Authored-By: Kazuki Yamada <koukun0120@gmail.com>
2025-05-24 11:34:56 +09:00
Kazuki Yamada
8f9b307ffa refactor(core/git): Improve parseRemoteValue function formatting and add test for getRemoteRefs 2025-05-24 11:34:56 +09:00
Devin AI
9a7409f41c fix(core): Fix command injection vulnerability in git clone
Co-Authored-By: Kazuki Yamada <koukun0120@gmail.com>
2025-05-19 15:51:51 +00:00
Kazuki Yamada
9538395cdf refactor(core): Move Git-related modules to dedicated core/git directory 2025-05-19 14:53:28 +00:00