View Issue Details

IDProjectCategoryView StatusLast Update
0037376mantisbtapi restpublic2026-09-08 08:15
Reporterhetalp Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status newResolutionopen 
Product Version2.27.1 
Summary0037376: MantisBT REST API returns 302 redirect to login page instead of API response when using Authorization token
Description

The MantisBT REST API is currently not returning the expected API response when an API token is provided through the Authorization header.

When calling the REST API with a valid API token, the request is redirected to the Mantis login page instead of returning the requested API data.

API Request

curl -i \
  -H "Authorization: YOUR_VALID_API_TOKEN" \
  "http://support.svaapta.com/api/rest/index.php/projects"

Current Response

HTTP/1.1 302 Found
Location: http://support.svaapta.com/login_page.php?return=api%2Frest%2Findex.php

Expected Response

The API should authenticate the user using the supplied API token and return the requested project data, for example:

HTTP/1.1 200 OK
Content-Type: application/json

with the project information in the response body.

Investigation Performed

The following checks have been completed:

  1. The Authorization header is successfully reaching PHP.
HTTP_AUTHORIZATION=<token>
Authorization => <token>
  1. The REST index.php is being executed successfully.
REST INDEX EXECUTED
  1. AuthMiddleware.php is successfully loaded.
AUTH MIDDLEWARE FILE LOADED
  1. The API token was independently validated using MantisBT's api_token_get_user() function.
Token length: 32
User ID: 534
  1. The token successfully maps to the MantisBT user.
Username: hetal.parmar
  1. mci_check_login() also successfully authenticates the user.
mci_check_login: 534
  1. The following REST middleware files were reviewed:

    • CacheMiddleware.php
    • OfflineMiddleware.php
    • VersionMiddleware.php
    • AuthMiddleware.php
  2. The REST API is enabled in MantisBT configuration:

$g_webservice_rest_enabled = ON;

Environment

  • MantisBT REST API
  • PHP 8.1.x
  • Apache
  • OpenResty / Nginx reverse proxy
  • Docker
  • Slim Framework 3.x
  • API token authentication

Technical Observation

The API token itself is valid and the Authorization header reaches the REST endpoint correctly.

However, the request ultimately receives a 302 redirect to:

login_page.php?return=api/rest/index.php

This redirect is unexpected for an API-token-authenticated REST request.

AuthMiddleware normally returns 401 or 403 for authentication/authorization failures rather than a 302 login redirect.

Impact

REST API clients are currently unable to reliably access MantisBT REST endpoints using API token authentication.

This affects API integrations that depend on endpoints such as:

/api/rest/index.php/projects

Next Investigation

Trace the Slim middleware execution order and identify which component/code is generating the 302 redirect to login_page.php.

The following should be investigated:

  • AuthMiddleware execution
  • Slim middleware stack
  • ApiEnabledMiddleware
  • Mantis authentication/redirect functions
  • Any customizations or plugins that may trigger login redirects
  • Source of login_page.php?return=api/rest/index.php

Expected Resolution

The REST API should accept a valid API token from the Authorization header and return the requested API response without redirecting the request to the MantisBT login page.

TagsNo tags attached.

Activities

dregad

dregad

2026-09-08 07:17

developer   ~0071419

First of all, please note that release 2.27.1 is no longer supported.

You should at least upgrade to 2.28.4 (consider unpatched security issues !) and confirm that the problem is still present there.
Even better considering that token authentication is changing in upcoming 2.29.0 release, test with the latest development branch (download a nightly build).

For the record, I am regularly using the REST API without issues, so maybe the problem is specific to your environment.

hetalp

hetalp

2026-09-08 08:15

reporter   ~0071421

Okay, thank you. I will check the latest version.