🐛 fix(git):将SSH主机密钥检查从no改为yes以增强安全性

 feat(git):改进SSH URL检测和分支克隆逻辑
📝 docs(frontend):更新SSH公钥添加说明,移除CodeUp链接
This commit is contained in:
Image 2025-12-25 16:17:42 +08:00
parent b095e7aa6c
commit 597d19dbfe
3 changed files with 12 additions and 8 deletions

View File

@ -2319,7 +2319,7 @@ async def _get_project_root(
await emit(f"🔄 正在获取仓库: {repo_url}")
# 检测是否为SSH URLSSH链接不支持ZIP下载
is_ssh_url = repo_url.startswith('git@')
is_ssh_url = GitSSHOperations.is_ssh_url(repo_url)
# 解析仓库 URL 获取 owner/repo
parsed = urlparse(repo_url)
@ -2602,7 +2602,7 @@ async def _get_project_root(
async def run_default_ssh_clone():
return await asyncio.to_thread(
GitSSHOperations.clone_repo_with_ssh,
repo_url, ssh_private_key, base_path, "" # 空字符串表示使用默认分支
repo_url, ssh_private_key, base_path, branch
)
clone_task = asyncio.create_task(run_default_ssh_clone())

View File

@ -229,7 +229,7 @@ class GitSSHOperations:
return url.startswith('git@') or url.startswith('ssh://')
@staticmethod
def clone_repo_with_ssh(repo_url: str, private_key: str, target_dir: str, branch: str = "main") -> Dict[str, any]:
def clone_repo_with_ssh(repo_url: str, private_key: str, target_dir: str, branch: str = None) -> Dict[str, any]:
"""
使用SSH密钥克隆Git仓库
@ -260,7 +260,7 @@ class GitSSHOperations:
ssh_cmd_parts = [
'ssh',
'-i', key_file,
'-o', 'StrictHostKeyChecking=no',
'-o', 'StrictHostKeyChecking=yes',
'-o', 'UserKnownHostsFile=/dev/null',
'-o', 'PreferredAuthentications=publickey',
'-o', 'IdentitiesOnly=yes' # 只使用指定的密钥,不使用系统默认密钥
@ -270,7 +270,11 @@ class GitSSHOperations:
print(f"[Git Clone] Using DeepAudit SSH key only: {key_file}")
# 执行git clone
cmd = ['git', 'clone', '--depth', '1', '--branch', branch, repo_url, target_dir]
cmd = ['git', 'clone', '--depth', '1']
if branch: # 只有明确指定分支时才添加
cmd.extend(['--branch', branch])
cmd.extend([repo_url, target_dir])
result = subprocess.run(
cmd,
env=env,
@ -414,7 +418,7 @@ class GitSSHOperations:
cmd = [
'ssh',
'-i', key_file,
'-o', 'StrictHostKeyChecking=no',
'-o', 'StrictHostKeyChecking=yes',
'-o', 'UserKnownHostsFile=/dev/null',
'-o', 'ConnectTimeout=10',
'-o', 'PreferredAuthentications=publickey',
@ -444,7 +448,7 @@ class GitSSHOperations:
'output': f'提示服务器显示Anonymous表示公钥未添加到Git服务或未关联到您的账户。\n请在Git服务的设置中添加SSH公钥。\n\n原始输出:\n{output}'
}
# 检查是否认证成功必须有用户名不能是Anonymous
# 检查是否认证成功
success_indicators = [
('successfully authenticated', True), # GitHub
('hi ', True), # GitHub: "Hi username!"

View File

@ -487,7 +487,7 @@ export default function Account() {
)}
<p className="text-xs text-muted-foreground">
<a href="https://github.com/settings/keys" target="_blank" rel="noopener noreferrer" className="text-primary hover:underline">GitHub</a> <a href="https://gitlab.com/-/profile/keys" target="_blank" rel="noopener noreferrer" className="text-primary hover:underline">GitLab</a> <a href="https://codeup.aliyun.com/" target="_blank" rel="noopener noreferrer" className="text-primary hover:underline">CodeUp</a>
<a href="https://github.com/settings/keys" target="_blank" rel="noopener noreferrer" className="text-primary hover:underline">GitHub</a> <a href="https://gitlab.com/-/profile/keys" target="_blank" rel="noopener noreferrer" className="text-primary hover:underline">GitLab</a>
</p>
</div>