You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pattern: The Copilot auth routing code repeats the same GITHUB_SERVER_URL hostname parsing and .ghe.com classification in three separate helpers.
Locations: containers/api-proxy/providers/copilot-auth.js lines 94-109, 123-140, 224-239, and 280-295.
Impact: Security-critical auth routing logic is split across multiple copies, which increases the risk of drift when GHES/GHEC handling changes.
Evidence
// deriveCopilotApiTargetconstserverUrl=env.GITHUB_SERVER_URL;if(serverUrl){try{consthostname=newURL(serverUrl).hostname;if(hostname!=='github.com'){if(hostname.endsWith('.ghe.com')){constsubdomain=hostname.slice(0,-8);return`copilot-api.${subdomain}.ghe.com`;}return'api.enterprise.githubcopilot.com';}}catch{// Invalid URL — fall through to default}}
// deriveGitHubApiTargetconstserverUrl=env.GITHUB_SERVER_URL;if(serverUrl){try{consthostname=newURL(serverUrl).hostname;if(hostname!=='github.com'&&hostname.endsWith('.ghe.com')){constsubdomain=hostname.slice(0,-8);return`api.${subdomain}.ghe.com`;}}catch{// Invalid URL — fall through to default}}
Extract a shared helper that parses GITHUB_SERVER_URL once and returns a normalized host classification, for example resolveGithubServerHost(env) or classifyGithubEnterpriseHost(serverUrl). The three callers can then switch on a single shared result instead of reimplementing the URL parsing and .ghe.com detection logic.
Duplicate Code Opportunity
Summary
GITHUB_SERVER_URLhostname parsing and.ghe.comclassification in three separate helpers.containers/api-proxy/providers/copilot-auth.jslines 94-109, 123-140, 224-239, and 280-295.Evidence
Suggested Refactoring
Extract a shared helper that parses
GITHUB_SERVER_URLonce and returns a normalized host classification, for exampleresolveGithubServerHost(env)orclassifyGithubEnterpriseHost(serverUrl). The three callers can then switch on a single shared result instead of reimplementing the URL parsing and.ghe.comdetection logic.Affected Files
containers/api-proxy/providers/copilot-auth.js— lines 94-109containers/api-proxy/providers/copilot-auth.js— lines 123-140containers/api-proxy/providers/copilot-auth.js— lines 224-239containers/api-proxy/providers/copilot-auth.js— lines 280-295Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-07-19
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpgSee Network Configuration for more information.