Relationship Graph
View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0037333 | mantisbt | api rest | public | 2026-07-30 03:27 | 2026-09-09 19:19 |
| Reporter | khushal | Assigned To | dregad | ||
| Priority | normal | Severity | minor | Reproducibility | have not tried |
| Status | resolved | Resolution | fixed | ||
| Product Version | 2.28.0 | ||||
| Target Version | 2.29.0 | Fixed in Version | 2.29.0 | ||
| Summary | 0037333: Accept optional Bearer prefix on API token in Authorization header | ||||
| Description | The REST API only accepts the API token bare (Authorization: <token>). It rejects Authorization: Bearer <token>, which is the RFC 6750 convention and the default for most HTTP clients, SDKs, API tools, and AI agents. Users routinely send the Bearer form and get an authentication failure with no indication of the cause. Proposal: strip an optional, case-insensitive Bearer prefix before token lookup. The bare form remains fully supported, so the change is additive. Other schemes (e.g. Basic) are unaffected. Invalid tokens fail identically with or without the prefix, so no new failure path is introduced. | ||||
| Additional Information | |||||
| Tags | No tags attached. | ||||
|
@khushal, I noticed today that your PR introduced 2 minor issues in the unit tests
I'll take care of fixing 1. Regarding 2, while it's technically correct, I believe it would be preferable for the tests to cover both $g_allow_anonymous_login usage scenarios, i.e.
Could you please send a PR amending the tests as described above ? |
|
|
@dregad Here is the PR: 2271 — the test no longer skips, it now asserts both cases: |
|
|
MantisBT: master cf9fe3bf 2026-07-30 03:29 Committer: vboctor Details Diff |
Accept optional Bearer prefix on API token The REST API only accepted the API token bare ('Authorization: <token>') and rejected the RFC 6750 bearer form ('Authorization: Bearer <token>'). Bearer is what most HTTP clients, SDKs, API tools, and AI agents send by default, so users routinely got an authentication failure with no indication of the cause. api_token_parse_credentials() strips an optional 'Bearer ' prefix before the token lookup. The scheme name is matched case-insensitively, and SP or HTAB between the scheme and the token is tolerated per RFC 7230. Credentials using any other scheme (e.g. 'Basic ...') are returned unchanged and continue to fail token validation as before. The bare form remains fully supported, so the change is additive. An invalid token is handled identically with or without the prefix, so no separate code path or failure mode is introduced. Also documents both accepted forms in the OpenAPI and Swagger definitions. Fixes 0037333 |
Affected Issues 0037333 |
|
| mod - api/rest/mantisbt_openapi.yaml | Diff File | ||
| mod - api/rest/restcore/AuthMiddleware.php | Diff File | ||
| mod - api/rest/swagger.json | Diff File | ||
| mod - core/api_token_api.php | Diff File | ||
| add - tests/Mantis/ApiTokenApiTest.php | Diff File | ||
| add - tests/rest/RestAuthHeaderTest.php | Diff File | ||
|
MantisBT: master 085645cb 2026-08-03 07:25 Committer: vboctor Details Diff |
Return WWW-Authenticate header on 401 and finish bearer support |
Affected Issues 0037333 |
|
| mod - api/rest/api.postman_collection.json | Diff File | ||
| mod - api/rest/mantisbt_openapi.yaml | Diff File | ||
| mod - api/rest/restcore/AuthMiddleware.php | Diff File | ||
| mod - core/api_token_api.php | Diff File | ||
| mod - core/constant_inc.php | Diff File | ||
| mod - docbook/Developers_Guide/en-US/Api_Rest.xml | Diff File | ||
| mod - tests/Mantis/ApiTokenApiTest.php | Diff File | ||
| mod - tests/rest/RestAuthHeaderTest.php | Diff File | ||
|
MantisBT: master 11b27326 2026-08-30 05:21 Details Diff |
PHPUnit: data providers should be static Deprecation warning introduced by Issue 0037333. |
Affected Issues 0037333 |
|
| mod - tests/Mantis/ApiTokenApiTest.php | Diff File | ||
| mod - tests/rest/RestAuthHeaderTest.php | Diff File | ||
|
MantisBT: master 6a8b3192 2026-08-30 13:31 Details Diff |
PHPUnit: fail on all issues The CI builds are not marked as failed when those "secondary" issues occurs. It would be preferable if they did, so that problems are detected early, and fixed as part of the PR process. Recent examples: - Deprecated warnings introduced by Issue 0037333 - Skipped tests introduced by Issues 0032470, 0037333 |
Affected Issues 0032470, 0037333 |
|
| mod - phpunit.xml | Diff File | ||
|
MantisBT: master 8803f5d5 2026-09-03 18:41 Committer: community Details Diff |
Assert both anonymous login modes in REST auth header test Replaces the skip with assertions for both configurations: - no 401 when anonymous login is ON, - 401 with WWW-Authenticate when OFF. Fixes 0037333, PR https://github.com/mantisbt/mantisbt/pull/2271 |
Affected Issues 0037333 |
|
| mod - tests/rest/RestAuthHeaderTest.php | Diff File | ||
|
MantisBT: master 9ece70d4 2026-09-03 19:11 Details Diff |
REST API auth without Bearer scheme is deprecated Update documentation to reflect that. Fixes 0035286, 0037333 |
Affected Issues 0035286, 0037333 |
|
| mod - api/rest/mantisbt_openapi.yaml | Diff File | ||
| mod - docbook/Developers_Guide/en-US/Api_Rest.xml | Diff File | ||
related to
child of
duplicate of