Skip to content

Projects Gantt tab: request values written unescaped into document.write() (reflected XSS) #542

Closed

Description

@caseysoftware

Where

modules/projects/viewgantt.php L173–174 (Projects → Gantt tab; also included by the department and user Gantt tabs):

$src = '?m=projects&a=gantt&suppressHeaders=1' . ... . "&showLabels=$showLabels&sortTasksByName=$sortTasksByName&proFilter=$proFilter&showInactive=$showInactive&company_id=$company_id&department=$department&dept_ids=$dept_ids&showAllGantt=$showAllGantt&user_id=$user_id&addPwOiD=$addPwOiD";
echo "<script>document.write('<img src=\"$src\">')</script>";

Problem

Several values go into a single-quoted JavaScript string without any escaping:

Variable Source
$user_id w2PgetParam($_GET, 'user_id', …) (L13)
$addPwOiD w2PgetParam($_POST, 'add_pwoid', …) (L22)
$proFilter raw $_POST['proFilter'], saved in session state (L37–40)
$dept_ids, $department globals set by the including tab

w2PgetParam() only runs strip_tags(), which leaves ' and ) alone. A value such as user_id=1');alert(document.cookie);// closes the string and runs script, so a crafted link is enough for the GET case. The proFilter value is kept in the session, so it runs again on every later visit to the tab in that session.

Found by code reading on master 8727ad5; not yet reproduced in a browser.

Proposed fix

  • Cast the numeric values (user_id, addPwOiD, proFilter, company_id, department) with (int), and reduce dept_ids to a comma list of ints.
  • Check proFilter against the keys of $projFilter before saving it to state.
  • Build the query string with http_build_query().
  • Replace document.write() with a plain <img id="ganttImg"> and set its src from JS: pass the server-built URL through json_encode(..., JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) and append &width= in JS. The same helper can serve the task and project designer gantts (see the related issues).

Testing

  • Open the Projects Gantt tab with &user_id=1');alert(1);// before and after: no alert after the fix, and the chart still renders.
  • POST proFilter containing a quote; the saved state should come back as an int.
  • For normal values the generated image URL is unchanged.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions