Skip to content

Commit 25f6ec4

Browse files
committed
security(copilot): strip response body from validation exception messages
The validation throws added in the previous fix included Truncate(body) in the missing-token path. Even though the validation only runs on a 2xx response that nominally has no usable token, a pathological response body could still contain a token-shaped substring. Exception messages land in daemon.log and bug-report attachments — best practice is to never include token-exchange response bodies in messages we don't strictly need. Endpoint URL + missing-field indicator is sufficient for diagnostics without any risk of leaking a credential into logs. expires_at value (integer, never a credential) remains in its message. Found during a pre-merge security audit.
1 parent 89514a3 commit 25f6ec4

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/Netclaw.Providers/GitHubCopilot/CopilotTokenExchanger.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,18 @@ private async Task<CachedToken> ExchangeAsync(string oauthToken, CancellationTok
118118
// Token=null/ExpiresAt=0 and we'd cache a useless Bearer. Validate
119119
// here so the failure surfaces at the exchange boundary, not later
120120
// when the chat call returns 401.
121+
//
122+
// We deliberately do NOT include the raw response body in these
123+
// exception messages — even on validation failure, the body of a
124+
// 200 response from /copilot_internal/v2/token may still contain a
125+
// token-shaped string, and exception messages can land in logs or
126+
// bug reports. The endpoint URL and the missing-field indicator
127+
// are sufficient for diagnostics.
121128
if (string.IsNullOrWhiteSpace(parsed.Token))
122129
{
123130
throw new InvalidOperationException(
124131
$"GitHub Copilot token exchange at {TokenEndpoint} returned a "
125-
+ $"payload with no 'token' field: {Truncate(body)}");
132+
+ "payload with no 'token' field.");
126133
}
127134

128135
if (parsed.ExpiresAt <= 0)

0 commit comments

Comments
 (0)