Skip to content

Task Gantt ignores the browser width on PHP 8.1+ (htmlspecialchars() inside a JS string) #544

Open

Description

@caseysoftware

Where

modules/tasks/viewgantt.php L324–340 (project Gantt tab and the to-do Gantt):

$src = ('?m=tasks&a=gantt&suppressHeaders=1&f=all&project_id=' . $project_id ...
        . "&width=' + ((navigator.appName=='Netscape'"
        . "?window.innerWidth:document.body.offsetWidth)*0.95) + '"
        . '&showLabels=' . $showLabels ...);
?>
<script> document.write('<img alt="..." src="<?php echo htmlspecialchars($src); ?>" />') </script>

Problem

$src contains JavaScript (' + (...) + ') that is meant to compute the width in the browser. Since PHP 8.1, htmlspecialchars() defaults to ENT_QUOTES, so every ' becomes &#039;:

&width=&#039; + ((navigator.appName==&#039;Netscape&#039;?...)*0.95) + &#039;&showLabels=...

Inside a <script> element entities aren't decoded, so the JS concatenation never runs; the HTML parser then decodes the entities when document.write() emits the <img>, and the browser requests width=' + ((navigator... literally. In modules/tasks/gantt.php L90, min(w2PgetParam($_GET, 'width', 600), 1400) compares that non-numeric string with 1400 and returns the string; GanttRenderer::__construct() casts it to (int) 0, so the chart is drawn at JpGraph's automatic width instead of 95% of the window.

The escaping is also in the wrong context: HTML-escaping a value that sits inside a JavaScript string literal. It isn't exploitable as written (the entities keep quotes inert), but it's the pattern behind #542.

Found by code reading on master 8727ad5 and by running htmlspecialchars() on PHP 8; not yet checked in a browser.

Proposed fix

Same helper as #542 / #543: build the server-side query with http_build_query() (casting the flags and ids to int), output a plain <img>, and set its src from JS using json_encode() for the server part plus the computed width. Also make gantt.php read the width with (int) before min(), with a sane lower bound.

Testing

  • Project → Gantt tab on PHP 8.1+: before the fix the image request has width=%27%20+%20((navigator...; after it, width=<number> and the chart fills ~95% of the window.
  • Same for Tasks → To-do → Gantt.
  • addLinksToGantt=1 still forces 1450px.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions