View Issue Details

IDProjectCategoryView StatusLast Update
0035039mantisbtreportspublic2025-03-01 18:40
Reporterraspopov Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.27.0 
Target Version2.27.1Fixed in Version2.27.1 
Summary0035039: The GraphViz tool is almost impossible to customise for Windows
Description

Setting the $g_graphviz_path option to 'C:\Program Files\Graphviz\bin\' will not work due to un-escaped spaces in the path and incorrectly escaped directory delimiter slashes in the proc_open() call at "core\graphviz_api.php".

TagsNo tags attached.

Relationships

related to 0026091 closedatrol CVE-2019-15715: [Admin Required - Post Authentication] Command Execution / Injection Vulnerability 
related to 0035038 resolvedcommunity Text on the relationship and workflow graphs are rendered cropped 

Activities

raspopov

raspopov

2024-11-26 14:01

reporter   ~0069494

PR: https://github.com/mantisbt/mantisbt/pull/2052

dregad

dregad

2024-11-27 07:59

developer   ~0069497

Last edited: 2024-11-27 08:01

The escapeshellcmd() call that is being removed in the proposed PR, was added as part of 0026091 to fix a security issue, so I'm reluctant to remove it, even though it is unlikely that this could be used as an attack vector since $g_graphviz_path can only be altered via changes in config_inc.php.

Since PHP 7.4, the command executed in proc_open() can be given as an array; according to the documentation In this case the process will be opened directly (without going through a shell) and PHP will take care of any necessary argument escaping, so maybe a better solution would be

        # Start dot process
-       $t_command = escapeshellcmd( $this->tool_path() . ' -T' . $p_format );
+       $t_command = [$this->tool_path() , ' -T' . $p_format];

I do not have a Windows environment to test this on, maybe you can confirm ? I will test on Linux later.

diedie2

diedie2

2024-11-27 10:59

reporter   ~0069498

I had the issue a few months ago. After a tip from atrol I just placed it directly on C: and then set

$g_dot_tool = 'C:\Graphviz\bin\dot.exe';
$g_neato_tool = 'C:\Graphviz\bin\dot.exe -Kneato';

In the config. I don't have $g_graphviz_path in my config.
Works perfectly!

Perhaps you could do the same?

dregad

dregad

2024-11-27 12:05

developer   ~0069500

@diedie2

$g_dot_tool = 'C:\Graphviz\bin\dot.exe';
$g_neato_tool = 'C:\Graphviz\bin\dot.exe -Kneato';

Since 2.27.0, these 2 configs have been obsoleted, and are no longer used anywhere in the codebase. You can remove them from your config...

I don't have $g_graphviz_path in my config.

The path to the tools is built dynamically from $g_graphviz_path (default value is /usr/bin/), concatenated with the tool name (dot, neato or circo) and .exe is appended if on Windows. I don't understand how proc_open() could actually find and execute a command in C:\Graphviz\bin, it would be interesting to find out what is happening.

raspopov

raspopov

2024-11-27 22:36

reporter   ~0069504

it would be interesting to find out what is happening.

Probably:

  1. He has no spaces in the tool path.
  2. He added Graphviz path to the PATH enviroment variable.
  3. He has no check is_executable() in MantisBT, otherwise simple concatenation of tool path and tool name should not work.
diedie2

diedie2

2024-11-28 06:04

reporter   ~0069506

@degrad I'm currently still on 2.62.2, but thx but the heads-up this has been changed. The space in in the original path (I had Program Files first to) was the problem for me. Thats why @atrol suggested to place it directly on C: so there are no spaces in the path. I left it there bc our server is dedicated for mantisbt.

dregad

dregad

2024-11-28 06:35

developer   ~0069507

OK that explains it. Thanks for the feedback @diedie2.

raspopov

raspopov

2024-11-28 10:23

reporter   ~0069508

$t_command = [$this->tool_path() , ' -T' . $p_format];

Unfortunately it doesn't work that way on Windows, plus it requires PHP 7.4.0.

I doubt that the escapeshellcmd() function is needed at all in this case, because there is code above that checks the program path for validity by is_executable().

I have tried many options over many hours and the best one is this, it also does the correct masking of spaces:

$t_command = escapeshellarg( $this->tool_path() ) . ' -T' . $p_format;

I have refreshed PR.

raspopov

raspopov

2024-11-28 10:28

reporter   ~0069509

In the PR I also added realpath() for Graphviz tools it efficiently fixes any problems with path including wrong directory separators and missing trailing separator.

dregad

dregad

2024-11-29 03:00

developer   ~0069512

Last edited: 2024-11-29 03:01

Unfortunately it doesn't work that way on Windows

So you're saying that this standard PHP syntax does not work on Windows ? The manual states that command may be passed as array of command parameters. In this case the process will be opened directly (without going through a shell) and PHP will take care of any necessary argument escaping..

I must admit I do not fully understand what the following note implies: On Windows, the argument escaping of the array elements assumes that the command line parsing of the executed command is compatible with the parsing of command line arguments done by the VC runtime.

it requires PHP 7.4.0.

Indeed, but this is the minimum required version to run MantisBT, so no problem here.

raspopov

raspopov

2024-11-29 08:51

reporter   ~0069513

Last edited: 2024-11-29 08:52

So you're saying that this standard PHP syntax does not work on Windows ?

I'm not quite sure but I suspect it does the same thing as escapeshellcmd() but internally so no error returns and result is empty, I also monitored file openings with Process Monitor (by Mark Russinovich) and saw no attempt to open or execute any file with good or bad paths. Maybe it depends on the Apache or PHP configuration.

Related Changesets

MantisBT: master-2.27 a6e8c5c7

2024-11-26 13:51

raspopov

Committer: dregad


Details Diff
Fix Graphviz calls on Windows

Failing due to unescaped spaces in the path and incorrectly escaped
directory delimiter slashes in the proc_open() call.

Use realpath() to set the path to the library, and add escapeshellarg()
in the Graphviz tool call.

Fixes 0035039

Signed-off-by: Damien Regad <dregad@mantisbt.org>

Original commits squashed.
Affected Issues
0035039
mod - admin/check/check_display_inc.php Diff File
mod - core/graphviz_api.php Diff File

MantisBT: master-2.27 b84319e7

2024-12-09 10:49

raspopov

Committer: dregad


Details Diff
New Graph::graphviz_path() function avoids duplicate code

Issue 0035039
Affected Issues
0035039
mod - admin/check/check_display_inc.php Diff File
mod - core/graphviz_api.php Diff File