-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDFReports: TCPDF temporary subject to open_basedir restriction #1656
Comments
Another side-effect of falling back to the system wide temp folder is running into open basedir restrictions. |
PDFReport Cache Folders are not in Piwik 1.0 installation package libs/tcpdf/cache please put those folders in package. greetings |
machoyer, why is it important to put these folders in Piwik? epinci, does TCPDF currently use cache? if so, did you test a K_PATH_CACHE value that would work and use piwik/tmp/ folders? Thanks |
I'm not sure how to fix this issue, since the K_PATH_CACHE should be piwik/tmp/ probably, but I wouldn't want to modify the tcpdf_config.php - it looks like TCPDF doesn't allow to modify the value appart from editing this file directly (if we define it upstream, there will be a PHP error "CONSTANT already defined"...). |
If someone experiences this issue please comment and we can try to fix the path, since I'm unable to reproduce. |
I haven't had the PDF Reports activated until I had upgraded to piwik v1.1.1 The problem appears everytime I try to download the PDF report. Trying to send it via mail hangs at "Loading Data". Backtrace: Warning: imagepng() href='function.imagepng'>function.imagepng</a>: open_basedir restriction in effect. File(/tmp/jpg_SNJixl) is not within the allowed path(s): (/var/www/web352/html/:/var/www/web352/phptmp/:/var/www/web352/files/:/var/www/web352/atd/:/usr/share/php/) in /var/www/web352/html/piwik/libs/tcpdf/tcpdf.php on line 7545 Backtrace --> There is an error. Please report the message and full backtrace in the Piwik forums. Warning: imagepng() href='function.imagepng'>function.imagepng</a>: Invalid filename in /var/www/web352/html/piwik/libs/tcpdf/tcpdf.php on line 7545 Backtrace --> There is an error. Please report the message and full backtrace in the Piwik forums. Warning: fopen() href='function.fopen'>function.fopen</a>: open_basedir restriction in effect. File(/tmp/jpg_SNJixl) is not within the allowed path(s): (/var/www/web352/html/:/var/www/web352/phptmp/:/var/www/web352/files/:/var/www/web352/atd/:/usr/share/php/) in /var/www/web352/html/piwik/libs/tcpdf/tcpdf.php on line 7611 Backtrace --> There is an error. Please report the message and full backtrace in the Piwik forums. Warning: fopen(/tmp/jpg_SNJixl) href='function.fopen'>function.fopen</a>: failed to open stream: Die Operation ist nicht erlaubt in /var/www/web352/html/piwik/libs/tcpdf/tcpdf.php on line 7611 Backtrace --> TCPDF ERROR: Can't open image file: /tmp/jpg_SNJixl |
Please set the priority of this bug higher. It effects every installation that has open_basedir restrictions. AFAIK, using open_basedir is a well established php security practice, I'm surprised that at least one of the developers (matt) isn't using it. You hit this bug every time that you upgrade because a new libs/tcpdf directory without the cache and images directories gets created. The problem is not the cache, but the images directory. tcpdf creates temporary png files for inclusion in the PDF report and that fails because the images subdirectory doesn't exist. |
bolero, if you are able to provide a patch it would help! thank you |
Hm, the site seems to experience problems today. I wasn't able to submit or access the tracker for some hours. I didn't change any code. The problem appeared after the 1.1.1 upgrade and so I searched the forum and found the problem and the solution in the German forum. I'm surprised that it wasn't mentioned in the English forum. Anyway, here's the link: http://forum.piwik.org/read.php?5,53811 The solution is as I mentioned: create the cache and images directories within the tcpdf root with appropriate rights, e.g. in our case
so, simply adding the directories to the tcpdf install source should suffice. Maybe with 775 or 777 permissions, as 755 will probably not be sufficient for most installations. |
I'll look into a proper fix. We don't want temporary files created in core, libs, or plugins. If code is shared between multiple installations, there's the potential for conflict. |
Thanks! |
I've taken a look at my own tcpdf installation and found that it contains an images directory and also a cache directory. And both directories have content. Mostly images used for the examples and the tcpdf logo. So, the install source contains those directories. You must be removing them because you don't need the examples etc. |
We've already done an extensive license review. This was a pre-requisite to submitting Piwik to the FSF directory. http://directory.fsf.org/project/piwik/ TCPDF is actually LGPL v3. The LGPL terms are written as an addition to the GPL ... that's why you see both gpl.txt and lgpl-3.0.txt in the folder. LGPLv3 is compatible with GPLv3 license used by Piwik. Both licenses expressly allow derivatives (by addition, modification, omission, etc). The license requires that we provide source to what we distribute, so we are in compliance. On top of that, we preserve attribution and include a URL to the project in ./LEGALNOTICE. |
Ok, the proposed fix:
|
|
I think there is a new occurence of this bug maybe: http://forum.piwik.org/read.php?2,72150 |
re: comment:18 -- that's the same as comment:8 |
Creating the empty directories in tcpdf is not enough since they also require write persmissions. Not sure if we can chmod during install, or maybe throw an error when openbasedir restrictions are in place? |
We shouldn't create tmp files in libs because:
|
In case you do not want to create temporary files there then tcpdf should create them in the tmp directory the virtual host uses or the tmp directory piwik uses. The only option then is to change the define ('K_PATH_IMAGES', K_PATH_MAIN.'images/'); or ask Nicola for another way of setting his config options. |
I'll follow-up upstream ... it would be nice to have something simpler than comment:16. |
(In [4210]) fixes #1656 - custom config file to override K_PATH_CACHE and K_PATH_IMAGES
|
(In [4212]) refs #1656 - fix applied upstream |
(In [4213]) refs #1656 - revert part of r4212 back to mirror upstream; the "fix applied upstream" is in reference to r3587 |
PDF export is broken, is it workign for you? Warning: opendir(D:/piwik/svn/trunk/plugins/PDFReports/fonts/) href='function.opendir'>function.opendir</a>: failed to open dir: No error in D:\piwik\svn\trunk\libs\tcpdf\tcpdf.php on line 4716 Warning: readdir(): supplied argument is not a valid Directory resource in D:\piwik\svn\trunk\libs\tcpdf\tcpdf.php on line 4717 |
Can't check right now, but I know where the problem is. I'll fix when I get back home. Thanks. |
Cool, the problem is only with the fonts directory (once I copied over from tcpdf/fonts where it was expecting it in plugins/PDFReports/fonts PDF generation was working) |
(In [4224]) fixes #1656 |
Update: we'll have to continue using the custom config file in plugins/PDFReports/config because the patch I submitted upstream was rejected. |
drwxr-xr-x 6 apache apache 4096 Jan 11 16:15 . That's scarry!!! This is not definitely written with web security in mind. I just fetched the source and try to install piwik but cannot do so without putting my web server in a risky situation.
I have not find a config variable or method in piwik to put my tmp directory and config directory outside the web root yet; so, i am not using this for web security reason. on older version of piwik (maybe 4-5 years back), i was able to put the config outside the web root. i found this: #8120 web security is definitely not what piwik wants to deal with. thomaszbz made an excellent point but seems to be shutdown for giving an excellent security critic. |
piwik\libs\tcpdf\config\tcpdf_config.php defines K_PATH_CACHE defaulting to the non existing folder piwik\libs\tcpdf\cache.
On most system this will cause tempnam functions to failback to system wide temp folder (as opposed to the expected piwik\tmp\cache).
On Windows system this will default to C:\Windows\temp that is often (very) out of the open_basedir causing the PDF generation to fail with stack dump.
Tcpdf cache folder should default to piwik installation cache folder.
The text was updated successfully, but these errors were encountered: