splitbrain / dokuwiki-plugin-dw2pdf

A fork of Luigi Micco's PDF export plugin for DokuWiki
http://www.dokuwiki.org/plugin:dw2pdf
55 stars 68 forks source link

Handle cases when there is an open_basedir restriction in effect #453

Closed jeffchulg closed 2 years ago

jeffchulg commented 2 years ago

Hi,

I experience issues with restrictions on open_basedir. The only allowed full path is the one in which the application resides.

Example :

is_file(): open_basedir restriction in effect. File(/lib/styles/../images/error.png) is not within the allowed path(s): (/appdata/sites/MyWiki:/appdata/runtime/MyWiki) in /appdata/sites/MyWiki/lib/plugins/dw2pdf/vendor/mpdf/mpdf/src/Mpdf.php on line 11455

I tried to set the basedir config, but if I do so, then the entire wiki is offline !

Klap-in commented 2 years ago

open_basedir is about the configuration of your system, something were dw2pdf cannot do much in my understanding. Otherwise, teach me please.

jeffchulg commented 2 years ago

Hi @Klap-in !

I agree, open_basedir is a configuration at system level. The only action the plugin can do is make a try...catch and check the exception.

However, if you look at the URI I provided, the plugin is requesting for /lib instead of DokuWiki Root directory followed by /lib....

The true issue is there and restriction on open_basedir is only the mean to get it.

jeffchulg commented 2 years ago

Linked to #448

Klap-in commented 2 years ago

lib/styles/../images/error.png is used in the css code, that is feeded to the mpdf library: e.g.

div.error {
  background-color: #fcc;
  background-image: url(/lib/styles/../images/error.png);
  border-color: #ebb;
}

I assume the mpdf library should recognize these url(/lib/localstufff....) and translate them to the actual file.

The error is I believe from that function that should do that. https://github.com/splitbrain/dokuwiki-plugin-dw2pdf/blob/8c25a9b93bde2c5f668be721ef62c58d442c2509/vendor/mpdf/mpdf/src/Mpdf.php#L11455

The is_file() checks if this is not a absolute file (e.g. in your case if the link was /appdata/sites/MyWiki/lib/styles/../images/error.png, but of course our link is in url(), so it should not yet be a file system path.

Ah, I see a recent version of mpdf has already fixed this. https://github.com/mpdf/mpdf/commit/130b5dbd20646edae84fe4ab1ef9674a9977dbd1

The image handling in mpdf is also changed, so doing next update needs more time.