T09 · Insecure Skill Coding Practices
- Location
scripts/gitlab_api.py:124- Finding
Access Token Sent to Arbitrary Clone Hosts and Persisted in Git Metadata
- Content
View full analysis
Dict: """Clone a GitLab repository to the specified directory""" parsed = urllib.parse.urlparse(repo_url) host = parsed.netloc or parsed.path.split('/')[0] if "://" in repo_url: path_parts = parsed.path.strip('/').rstrip('.git').split('/') project_path = '/'.join(path_parts) project_name = path_parts[-1] if path_parts else 'repo' else: match = re.match(r'[^@]+@([^:]+):(.+\.git)', repo_url) if match: host = match.group(1) project_path = match.group(2).rstrip('.git') project_name = project_path.split('/')[-1] else: return {"success": False, "error": "Invalid SSH URL format"} if target_dir is None: target_dir = Path.cwd() / project_name if target_dir.exists(): return {"success": False, "error": f"Directory already exists: {target_dir}"} clone_url = repo_url if repo_url.startswith('https://') and self.token: if '@' not in repo_url: auth_url = repo_url.replace( 'https://', f'https://oauth2:{self.token}@' ) clone_url = auth_url result = subprocess.run( ['git', 'clone', clone_url, str(target_dir)], capture_output=True, text=True, check=True ) ``` The resulting remote URL is subsequently retrieved: ```python result = subprocess.run( ['git', 'remote', 'get-url', 'origin'], cwd=repo_path, capture_output=True, text=True, check=True ) info["remote"] = result.stdout.strip() ``` The CLI prints the retrieved URL: ```python f"**Remote**: {info['remote']}\n" ``` ## ...[truncated 2256 chars]- Remediation
View remediation
