-
Notifications
You must be signed in to change notification settings - Fork 81
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
Block unfuzzed loaders with libvips 8.13+ #105
Comments
Thanks for the heads up. Any idea how to call it via ruby-vips? I'm guessing that's something that should be called globally at require time, rather than per image. |
Yes, this should be a global call. As far as I can see, there is no support for this in I am not sure of the proper way to handle this in |
Heroku have libvips in their stack images! https://devcenter.heroku.com/changelog-items/2549 But they include a lot of insecure load libraries :( Anyone using How about setting the edit sigh, the libvips that supports blocking is in ubuntu from 22.10, so won't be in heroku for ages. Blocking would still help people who have built their own libvips. |
The libvips versions in heroku stack images are old. It is better to continue using custom buildpacks. @jcupitt I maintain a custom buildpack here that has the latest libvips version (currently 8.14.1). I have read your suggestions on other buildpacks and used your docker files as reference. Any suggestions that can increase security and make the buildpack better are highly appreciated. |
Oh, nice @jonian! I'll open an issue with some comments. |
libvips/ruby-vips#382 has been merged a few months ago, and it should allow to block untrusted loaders by default. |
Since this is a global setting, I'm not sure it's a good idea for ImageProcessing gem to be overriding it, because it would change behavior of code that calls vips directly. If this could be set at the individual processing pipeline level, I would consider it. |
Should we mention ::Vips.block_untrusted(true) in the README? |
Maybe another option would be for I think "secure by default" is likely to be the best choice when dealing with untrusted data (ie. everyone who uses |
I'm planning to turn this on by default in the upcoming major version of ImageProcessing. |
May I object to the decision? I totally agree with your previous statement. |
The default could change, but not at a 3rd-party-gem level. |
ruby-vips is used quite widely outside Rails, so changing the default there would force a source code change on a lot of other projects. ImageProcessing is more specialised and really only deals with untrusted data so, to my mind, it's the least-worst place to do it. Perhaps the upcoming libvips 8.16 should simply block all unfuzzed loaders for everyone, with an env var allow list for people that are dealing with trusted data. Though it will cause a lot of people a lot of annoyance. |
I happen to be working on a Rails project that interacts directly with ruby-vips. I have a potential solution and a request from the top of my head. Potential solution: Making it obviousIn the README, we could add something to direct users to this flag they should be aware of. For example, add this to the example. require "image_processing/vips"
::Vips.block_untrusted(true) # add this
pipeline = ImageProcessing::Vips
.source(file)
.convert("png")
large = pipeline.resize_to_limit!(800, 800)
medium = pipeline.resize_to_limit!(500, 500)
small = pipeline.resize_to_limit!(300, 300)
Request: In case I cannot prevent
|
I think Ruby bindings for libvips isn't the appropriate abstraction level for turning this by default. ImageProcessing, on the other hand, is primarily intended for handling file attachments on the web (it's used by Active Storage, Shrine, CarrierWave and Refile), where files come from users. I agree with @jcupitt that it would make sense for ImageProcessing to provide secure defaults for the majority of web apps, and I already mentioned it would come with a major version bump and of course be documented. I don't really understand the need for an environment variable when |
One can set ::Vips.block_untrusted(false) but timing matters. People who want to, say, process SVG have to do that:
The problem is most of the time, we don't know when other places have done setting the flag. (The timing is unknown.) Interestingly, you, @janko, are probably the one who made me aware of the issue. If you plan to do it at some I might be wrong; if there is a better way to view the issue, please let me know. |
In this case, the fact that ImageProcessing autoloads the |
When to set the flag will never be obvious when there are multiple places setting the flag.The end consumers are probably not the ones who I can't even guess how people find out they have to look at this (the middle) gem's readme to be aware of the side effects. This is one of those situations when there is no right answer.
I don't know. |
You can always force gems to be required on gem "image_processing", "~> 2.0", require: "image_processing/vips"
ImageProcessing gem is intended to be used with file attachment libraries that accept images from the web, so this would be a secure default that some will want to opt out of, which is better than an insecure default that most will want to opt into (but won't, because it's not the default and they won't read the README). Rails also prioritizes security by default, and it's the biggest dependent of ImageProcessing. |
@janko Hey, thanks for the reply. I thought I got ghosted. ReferencesPlease refer to
How about when the variable is already set, The logic is that if the variable is set, but the library is operating in untrusted mode, it indicates that some other libraries are already called I haven't tried it personally, so I'm not quite sure if one can unblock after the environment variable is set. However, according to the document, it should work. In conclusion (TL;DR)The proposal is if |
Yes, that's completely reasonable, thanks for bringing it to my attention 👍 |
There is a new libvips 8.13+ to block unfuzzed loaders using
vips-block-untrusted-set
.I think this should be enabled by default to improve security, as most of the time the images processed by
image_processing
come from an user-controlled source.The text was updated successfully, but these errors were encountered: