gh-aw icon indicating copy to clipboard operation
gh-aw copied to clipboard

`400 bad request: Authorization header is badly formatted` - GHE

Open jaroslawgajewski opened this issue 5 months ago • 7 comments

Problem

Since the gh-aw v0.79.3 upgrade, every agentic workflow on GHE instance runs AWF v0.27.0, whose api-proxy sends a malformed Authorization header to the GHES Copilot endpoint. Execute GitHub Copilot CLI dies after 4 retries with:

400 bad request: Authorization header is badly formatted

Related gh-aw-firewall issue:

https://github.com/github/gh-aw-firewall/issues/4744

jaroslawgajewski avatar Jun 11 '26 11:06 jaroslawgajewski

fixed in AWF v0.27.2

jaroslawgajewski avatar Jun 11 '26 20:06 jaroslawgajewski

🔗 AWF tracking issue: https://github.com/github/gh-aw-firewall/issues/4744

Generated by Firewall Issue Dispatcher · ◷

lpcox avatar Jun 13 '26 13:06 lpcox

@lpcox unfortunatelly it seems that issue remains on GHES on 0.27.2 as well 😢 same error

jaroslawgajewski avatar Jun 15 '26 20:06 jaroslawgajewski

@jaroslawgajewski thanks for the report. the fix in v0.27.2 checks for rawTarget === 'api.enterprise.githubcopilot.com' to apply the token prefix but there are a few ways this might not have been enough. could you answer these questions (assuming there's no secret info). Thanks!

  1. Is COPILOT_API_TARGET set explicitly in your environment? If this is set to a custom hostname (e.g., your GHES instance URL), the previous fix won't match api.enterprise.githubcopilot.com.
  2. What is your GITHUB_SERVER_URL? If it's anything other than github.com or *.ghe.com, it should resolve to api.enterprise.githubcopilot.com.
  3. Are you using BYOK? If COPILOT_PROVIDER_TYPE is set (e.g., azure) or a BYOK API key is configured, the proxy intentionally uses Bearer even on GHES.
  4. Can you share the failing request's auth header? If you can run with AWF_LOG_LEVEL=debug or check token-diag.log in the AWF work directory, we can see whether the proxy is sending Bearer vs token and to which target.

lpcox avatar Jun 16 '26 00:06 lpcox

Thanks for the fast turnaround @lpcox Answers below

1. Is COPILOT_API_TARGET set explicitly? Yes - and I believe this is the miss. We set it explicitly to api.business.githubcopilot.com (we're on Copilot Business licenses, not Enterprise). The v0.27.2 fix keys on rawTarget === 'api.enterprise.githubcopilot.com', so for the Business endpoint the token-prefix branch never runs and the header goes out in the wrong form -> 400 … Authorization header is badly formatted. Same GHES symptom, just the business host rather than enterprise.

2. What is GITHUB_SERVER_URL? Our enterprise GHES instance - a *.ghe.com host. So by the hostname logic it would resolve to api.enterprise.githubcopilot.com, but because of the Business-license setup we override COPILOT_API_TARGET to api.business.githubcopilot.com. Net: the server is *.ghe.com (enterprise-class) yet the effective target is the Business host, which the exact-string check doesn't cover.

3. Are you using BYOK? No real BYOK - COPILOT_PROVIDER_TYPE is not set (no azure/custom provider), and there's no real provider key. We do set two placeholder values so the CLI runs in offline / credential-isolation mode: COPILOT_PROVIDER_API_KEY=placeholder-token-for-credential-isolation plus a dummy BYOK key var.

4. Can you share the failing request's auth header? It fails on every attempt with 400 bad request: Authorization header is badly formatted (all retries exhausted, then exit 1).

For scope: pinning AWF to the latest 0.25.x line avoids this entirely (our current workaround), so the regression is specifically in the 0.27.x target-detection path.

jaroslawgajewski avatar Jun 16 '26 17:06 jaroslawgajewski

thanks @jaroslawgajewski this is helpful. we're looking into it

lpcox avatar Jun 17 '26 03:06 lpcox

@lpcox I've pined gh-aw 0.79.8 to AWF 0.72.4 for testing and issue still persists 400 bad request: Authorization header is badly formatted

jaroslawgajewski avatar Jun 19 '26 10:06 jaroslawgajewski