View Issue Details

IDProjectCategoryView StatusLast Update
0037524mantisbtcode cleanuppublic2026-12-03 09:02
Reporterdombn Assigned Tocommunity  
PrioritynormalSeverityminorReproducibilityN/A
Status assignedResolutionopen 
Product Version2.29.0 
Summary0037524: Commands leak $g_project_override after execute() — add opt-in save/restore in Command
Description

Many commands set $g_project_override in validate() or process() and never restore it, so the override stays active for the rest of the request. This was discussed in https://github.com/mantisbt/mantisbt/pull/2317, where the Category commands got a save/restore in execute().

Proposal (agreed in the PR discussion): an opt-in protected helper setProjectOverride( $p_project_id ) in Command that records the previous value; execute() restores it in a finally block only if the helper was used. Commands are migrated one at a time together with their callers.

A blanket restore in the base class is not possible, because some callers rely on the override persisting after execute():

  • bug_view_inc.php after IssueViewPageCommand calls config_get() without a project id (action_button_position, time_tracking_view_threshold, …).
  • REST write endpoints that return mc_issue_get() after the command (issue add, note add/delete, file delete, relationship add/delete, monitor add, move): mci_issue_data_as_array() uses project-less config_get() (roadmap_view_threshold, enable_projection, enable_eta, …). GET /issues/{id} sets no override, so it already resolves these differently. Having mc_issue_get() set the issue's project itself would fix both.

Related findings to address in the same work:

  • ProjectDeleteCommand: the leaked override breaks the current-project check in manage_proj_delete.php, see 0037523.
  • Nested commands: IssueMoveCommand → IssueNoteAddCommand leaves the override on the target project, so EVENT_MOVE_BUG handlers see the target project when a note was added and the source project otherwise.
  • IssueRelationshipDeleteCommand::validate() assigns $g_project_override without a global declaration, so the override has no effect there.
Additional Information

I'll provide a PR.

TagsNo tags attached.

Relationships

related to 0037523 confirmedcommunity Deleting any project resets the current project selection to All Projects 

Activities

There are no notes attached to this issue.