mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-31 19:22:15 +08:00
fix(copilot): unify request fingerprint across all Copilot API calls
- Make header constants in copilot_auth.rs public, add COPILOT_INTEGRATION_ID - Unify User-Agent across 4 internal methods (eliminate "CC-Switch" leakage) and version string - claude.rs add_auth_headers now references shared constants, adds user-agent / api-version / openai-intent - forwarder.rs filters all 6 fixed fingerprint headers for Copilot requests to prevent reqwest append duplication - stream_check.rs health check pipeline aligned with new fingerprint
This commit is contained in:
@@ -346,12 +346,15 @@ impl ProviderAdapter for ClaudeAdapter {
|
||||
AuthStrategy::Bearer => {
|
||||
request.header("Authorization", format!("Bearer {}", auth.api_key))
|
||||
}
|
||||
// GitHub Copilot: Bearer + 特定的 Editor headers
|
||||
// GitHub Copilot: Bearer + 统一指纹头
|
||||
AuthStrategy::GitHubCopilot => request
|
||||
.header("Authorization", format!("Bearer {}", auth.api_key))
|
||||
.header("Editor-Version", "vscode/1.85.0")
|
||||
.header("Editor-Plugin-Version", "copilot/1.150.0")
|
||||
.header("Copilot-Integration-Id", "vscode-chat"),
|
||||
.header("editor-version", super::copilot_auth::COPILOT_EDITOR_VERSION)
|
||||
.header("editor-plugin-version", super::copilot_auth::COPILOT_PLUGIN_VERSION)
|
||||
.header("copilot-integration-id", super::copilot_auth::COPILOT_INTEGRATION_ID)
|
||||
.header("user-agent", super::copilot_auth::COPILOT_USER_AGENT)
|
||||
.header("x-github-api-version", super::copilot_auth::COPILOT_API_VERSION)
|
||||
.header("openai-intent", "conversation-panel"),
|
||||
_ => request,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +46,11 @@ const TOKEN_REFRESH_BUFFER_SECONDS: i64 = 60;
|
||||
const COPILOT_MODELS_URL: &str = "https://api.githubcopilot.com/models";
|
||||
|
||||
/// Copilot API Header 常量
|
||||
const COPILOT_EDITOR_VERSION: &str = "vscode/1.96.0";
|
||||
const COPILOT_PLUGIN_VERSION: &str = "copilot-chat/0.26.7";
|
||||
const COPILOT_USER_AGENT: &str = "GitHubCopilotChat/0.26.7";
|
||||
const COPILOT_API_VERSION: &str = "2025-04-01";
|
||||
pub const COPILOT_EDITOR_VERSION: &str = "vscode/1.96.0";
|
||||
pub const COPILOT_PLUGIN_VERSION: &str = "copilot-chat/0.26.7";
|
||||
pub const COPILOT_USER_AGENT: &str = "GitHubCopilotChat/0.26.7";
|
||||
pub const COPILOT_API_VERSION: &str = "2025-04-01";
|
||||
pub const COPILOT_INTEGRATION_ID: &str = "vscode-chat";
|
||||
|
||||
/// Copilot 使用量 API URL
|
||||
const COPILOT_USAGE_URL: &str = "https://api.github.com/copilot_internal/user";
|
||||
@@ -465,6 +466,7 @@ impl CopilotAuthManager {
|
||||
.http_client
|
||||
.post(GITHUB_DEVICE_CODE_URL)
|
||||
.header("Accept", "application/json")
|
||||
.header("User-Agent", COPILOT_USER_AGENT)
|
||||
.form(&[("client_id", GITHUB_CLIENT_ID), ("scope", "read:user")])
|
||||
.send()
|
||||
.await?;
|
||||
@@ -502,6 +504,7 @@ impl CopilotAuthManager {
|
||||
.http_client
|
||||
.post(GITHUB_OAUTH_TOKEN_URL)
|
||||
.header("Accept", "application/json")
|
||||
.header("User-Agent", COPILOT_USER_AGENT)
|
||||
.form(&[
|
||||
("client_id", GITHUB_CLIENT_ID),
|
||||
("device_code", device_code),
|
||||
@@ -948,7 +951,9 @@ impl CopilotAuthManager {
|
||||
.http_client
|
||||
.get(GITHUB_USER_URL)
|
||||
.header("Authorization", format!("token {}", github_token))
|
||||
.header("User-Agent", "CC-Switch")
|
||||
.header("User-Agent", COPILOT_USER_AGENT)
|
||||
.header("Editor-Version", COPILOT_EDITOR_VERSION)
|
||||
.header("Editor-Plugin-Version", COPILOT_PLUGIN_VERSION)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -978,9 +983,9 @@ impl CopilotAuthManager {
|
||||
.http_client
|
||||
.get(COPILOT_TOKEN_URL)
|
||||
.header("Authorization", format!("token {}", github_token))
|
||||
.header("User-Agent", "CC-Switch")
|
||||
.header("Editor-Version", "vscode/1.85.0")
|
||||
.header("Editor-Plugin-Version", "copilot/1.150.0")
|
||||
.header("User-Agent", COPILOT_USER_AGENT)
|
||||
.header("Editor-Version", COPILOT_EDITOR_VERSION)
|
||||
.header("Editor-Plugin-Version", COPILOT_PLUGIN_VERSION)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user