Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Relay GitHub API error messages to the user on auth failures#12737

Merged
Seldaek merged 1 commit into
composer:mainfrom
QDenka:fix/github-error-message-relay
Mar 4, 2026
Merged

Relay GitHub API error messages to the user on auth failures#12737
Seldaek merged 1 commit into
composer:mainfrom
QDenka:fix/github-error-message-relay

Conversation

@QDenka
Copy link
Copy Markdown
Contributor

@QDenka QDenka commented Feb 8, 2026

Summary

When a GitHub API request fails with 401/403, Composer now extracts and displays the actual error message from GitHub's JSON response body instead of showing a generic message about reviewing OAuth tokens or accessing private repos.

Problem

As described in #12711, when GitHub returns specific error messages like:

  • organization forbids access via a personal access token (classic)
  • organization forbids access via fine-grained personal access tokens if the token's lifetime is greater than 366 days

Composer would only show a generic message suggesting to review your GitHub OAuth token or create one to access private repos. This made it very difficult to diagnose the actual issue.

Solution

Added an optional $responseBody parameter to AuthHelper::promptAuthIfNeeded(). For GitHub domains, when a 401/403 response is received (and it's not a rate limit or SSO issue), the method now attempts to decode the JSON response body and extract the message field from GitHub's API response.

The extracted message is then displayed to the user, providing accurate information about why the request failed.

Changes

  • src/Composer/Util/AuthHelper.php: Added $responseBody parameter and GitHub API error message extraction logic
  • src/Composer/Util/Http/CurlDownloader.php: Pass response body to promptAuthIfNeeded()

Fixes #12711

When a GitHub API request fails with 401/403, Composer now extracts
and displays the error message from GitHub's JSON response body.

Previously, the error message would only suggest reviewing the OAuth
token or creating one to access private repos, even when the actual
issue was something else entirely (e.g. organization token policy
restrictions).

Fixes composer#12711
@Seldaek Seldaek added this to the 2.9 milestone Mar 4, 2026
@Seldaek Seldaek merged commit 68aff4e into composer:main Mar 4, 2026
21 checks passed
@Seldaek
Copy link
Copy Markdown
Member

Seldaek commented Mar 4, 2026

Thanks

mwalbeck pushed a commit to mwalbeck/docker-composer that referenced this pull request Apr 26, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [composer/composer](https://github.com/composer/composer) | patch | `2.9.5` → `2.9.7` |

---

### Release Notes

<details>
<summary>composer/composer (composer/composer)</summary>

### [`v2.9.7`](https://github.com/composer/composer/blob/HEAD/CHANGELOG.md#297-2026-04-14)

[Compare Source](composer/composer@2.9.6...2.9.7)

- Fixes regression calling custom script command aliases that are called a substring of a composer command ([#&#8203;12802](composer/composer#12802))

### [`v2.9.6`](https://github.com/composer/composer/blob/HEAD/CHANGELOG.md#296-2026-04-14)

[Compare Source](composer/composer@2.9.5...2.9.6)

- Security: Fixed command injection via malicious Perforce reference (GHSA-gqw4-4w2p-838q / CVE-2026-40261)
  - Security: Fixed command injection via malicious Perforce repository definition (GHSA-wg36-wvj6-r67p / CVE-2026-40176)
  - Security: Fixed git credentials remaining in git mirror .git/config after clone or update failed ([`2bcbfc3`](composer/composer@2bcbfc3d))
  - Security: Fixed usage of insecure 3DES ciphers when ext-curl is missing ([`5e71d77`](composer/composer@5e71d77e))
  - Security: Fixed Perforce unescaped user input in queryP4User shell command ([`ef3fc08`](composer/composer@ef3fc088))
  - Security: Hardened git/hg/perforce/fossil identifier validation to ensure branch names starting with `-` do not cause issues ([`6621d45`](composer/composer@6621d45), [`d836b90`](composer/composer@d836b90), [`5e08c76`](composer/composer@5e08c764))
  - Fixed inconsistent treatment of SingleCommandApplication script commands wrt autoloading ([#&#8203;12758](composer/composer#12758))
  - Fixed GitHub API authentication errors not being visible to the user ([#&#8203;12737](composer/composer#12737))
  - Fixed some platform package parsing failing when Composer runs in web SAPIs ([#&#8203;12735](composer/composer#12735))
  - Fixed error reporting for clarity when a constraint cannot be parsed ([#&#8203;12743](composer/composer#12743))

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDQuNCIsInVwZGF0ZWRJblZlciI6IjQzLjEwNC40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: https://git.walbeck.it/mwalbeck/docker-composer/pulls/1130
Co-authored-by: renovate-bot <[email protected]>
Co-committed-by: renovate-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHub access token message should give more accurate information on why the existing token failed

2 participants