-
Notifications
You must be signed in to change notification settings - Fork 338
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
Cache directory should default to PHP temporary directory #71
Comments
Configuration workaround, but again, this should be the default: $html_purifier_cache_dir = sys_get_temp_dir() . '/HTMLPurifier/DefinitionCache';
if (!is_dir($html_purifier_cache_dir)) {
mkdir($html_purifier_cache_dir, 0770, TRUE);
}
$config->set('Cache.SerializerPath', $html_purifier_cache_dir); |
This is a bit tricky, what are you supposed to do if |
there are pros and cons for changing the cache dir. But surely it'll be logical to not giving writable permission to folders which is in vendors folder (for composer). Also it is not sensible to change the folder permissions after every composer update.. |
I think we can throw an error if the cache dir was not set... |
I'd prefer not to break people's code upon an upgrade, if it was working before. But I think a mode to let the user completely manually manage the cache directory would be quite reasonable. |
I pushed a possible patch to fix this, but I am not confident it works. Could y'all apply the patch, set Cache.SerializerPermissions to NULL and see if that works? |
Well, we'll do a release with this, and bugfix if it doesn't work. |
I still get this error: as @fluxsauce said |
@alexander-schranz Try this commit 1ef4375 does it solve your problem? |
@ezyang still same message The message come from: https://github.com/ezyang/htmlpurifier/blob/master/library/HTMLPurifier/DefinitionCache/Serializer.php#L289. If I look at this class I would recommend you not to set file permissions on runtime. This could change permissions which a user dont want and can open a security whole. I would just output a message when it is not writeable and not try to fix the permissions and it should not recommend to set it to 777. If it is just a read and write cache 660 should be enough for the correct webserver user. If you look at symfony they use a regex to get the correct webserver user: http://symfony.com/doc/current/setup/file_permissions.html#using-acl-on-a-system-that-supports-chmod-a-macos. |
Still getting this issue when using composer in a Laravel 5.1 project after install. Running on Linux Mint. What's the status on the recommended fix? |
@scottpidzarko I'm not sure how you define this in laravel but maybe this symfony service definition helps you: <service id="app.purifier.config" class="HTMLPurifier_Config">
<factory class="HTMLPurifier_Config" method="createDefault"/>
<call method="set">
<argument type="string">Cache.SerializerPath</argument>
<argument type="string">%app.purifier.serializer-path%</argument><!-- writeable folder path -->
</call>
<!-- other configurations -->
<call method="set">
<argument type="string">HTML.Allowed</argument>
<argument type="string">a[href],p,b,i,em,strong,ul,li,ol,s</argument>
</call>
</service>
<service id="app.purifier" class="HTMLPurifier">
<argument type="service" id="app.purifier.config"/>
</service> |
How to mate it with LaravelCreate the And add this code to the $this->app->bind(\HTMLPurifier_Config::class, function () {
$config = \HTMLPurifier_Config::createDefault();
$config->set('Cache.SerializerPath', storage_path('htmlPurifierCache'));
return $config;
});
$this->app->singleton(\HTMLPurifier::class, function (\Illuminate\Foundation\Application $app) {
return new \HTMLPurifier($app->make(\HTMLPurifier_Config::class));
}); To get a $purifier = app()->make(\HTMLPurifier::class); Or, if you make a controller method, add the class to the method arguments: public function action(\HTMLPurifier $purifier, Request $request)
{
// ...
} |
Why is this issue closed? Problem still exists... |
FYI for anyone following @Finesse 's suggestion, that |
I second that. And anyways, why does the definition need to be generated on the fly? It could just be packaged together with the rest of the library and all those problems here would be gone. |
Using
|
This is still broken for me. HTMLPurifier and capistrano are in a permisiions / chown death grapple. No other composer dependency does this. Please can it just write a cache to somewhere and then leave it alone! stop chowning and setting the permissions. seems like massive over reach. |
i'm trying to stop it by adding this doesn't make any difference. |
Would it be okay to re-open this issue? Not sure why it's marked as closed. |
Bump to this, still appears to be an issue in
Using The |
This issue is valid; the library should not attempt to write to vendor directory for its caching. The following issues are duplicates: |
Recently Updated via Composer and am getting this issue now when I didn't before. It still tells us to cmod to 777... and I did that, despite now finding issues saying not to do that, and it didn't even fix it anyway, so I reinstalled. I've tried downgrading to V4.16 and it lists it is 4.15 in the version, but it still has the same issue.
|
Is this package just no longer maintained? This has been an ongoing issue for a few years now! |
Edit: #373 (comment) The 777 issue is resolved, but the broader use of a vendor directory is still applicable. I'm no longer active in PHP, but they're still commits and PRs are accepted, so while I can't personally guarantee it'll be accepted, it'd be reasonable to expect that a PR would be considered. |
Basically, this one is kind of complicated and I haven't had time to figure out what we should do / how to fix it. If someone wants to come up with a proposal and explain why it is the right thing to do, and then send a PR, I can help shepherd it. But whatever the fix is also needs to not gratuitously break old installs and needs to handle edge cases involving tmp directories. |
That sounds very reasonable. Thank you for your continued support and the project! |
I mean, is this affecting anything? It feels like everything is working just fine, except I have this error screaming at me for no good reason clogging up my error logs. |
For anyone, you can disable the cache with
|
A site using htmlpurifier as part of a deployable artifact doesn't have access to write to the codebase, but htmlpurifier defaults to writing within the codebase, specifically:
The library should instead default to PHP's built-in temporary directory support.
Also, 777 is an extremely unsafe permission and should not be recommended, especially on a webserver.
The text was updated successfully, but these errors were encountered: