-
Notifications
You must be signed in to change notification settings - Fork 379
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
Images not generated when source path is out of root directory #780
Comments
@nicokaag: There has always been a check requiring you are within the root directory, only prior it didn't resolve paths to their real path. Why don't you just set a proper root path value for your specific setup via the configuration YML: liip_imagine:
loaders:
default:
filesystem:
data_root: "/your/data/root" Alternatively, if you are on Linux or FreeBSD, you can always bind one directory path (the folder outside your web root) to another (a folder inside your web root) like so:
|
a simple reason to not set the data_root in the configuration is, that there is difference per environment (staging/production). only way around that, is again a setting over the parameters.yml. |
@slaubi I disagree that blindly following symbolic links outside the defined data root should be acceptable behavior. I absolutely do not want any piece of code doing that without my explicit consent, as doing so negates the value of setting a data root entirely and opens the door to a host of security concerns. In the context of this bundle, "explicit consent" simply means setting the As for requiring different configuration depending on environment, I don't find it overly ambitious to ask users to utilize Symfony's build-in environment-specific configuration loading (via That being said, I am not a "bundle maintainer" so it is possible a PR relaxing this behavior would be accepted if you submitted one. As it stands, you need to do one of the following to allow for your images to be stored in an arbitrary location:
|
I now explicitly set the directory over the configuration. So I close this ticket because that does resolve my issue. |
This is quite messy to resolve if you're deploying to a large number of servers. And it's made trickier if you are using symlinks to achieve atomic-ish deployments, because your config.yml
parameters.php
I can't help but feel that there is a better solution than this, but I'm not convinced hard-coding the home directory into the parameters file is it. |
I'm not sure what your exact issue with configuration is, can you elaborate further? The
The configuration of the Default setup enables loading from the liip_imagine:
loaders:
default:
filesystem:
data_root: "%kernel.root_dir%/../web" Support for multiple paths enables loading from any number of directories: liip_imagine:
loaders:
default:
filesystem:
data_root:
- "%kernel.root_dir%/../web/foo"
- "%kernel.root_dir%/../web/bar"
- "%kernel.root_dir%/../web/baz" Support for named paths enables loading from any number of directories and explicity selecting a root path when calling our API: liip_imagine:
loaders:
default:
filesystem:
data_root:
foo: "%kernel.root_dir%/../web/foo"
bar: "%kernel.root_dir%/../web/bar"
baz: "%kernel.root_dir%/../web/baz" // load from the first root path where the image is found
<img src="<?php $this['imagine']->filter('path/to/file.ext', 'my_filter_set') ?>" />
// load from the "baz" path explicitly
<img src="<?php $this['imagine']->filter('@baz:path/to/file.ext', 'my_filter_set') ?>" /> Support for bundle-autoregistration allows you to automatically register the liip_imagine:
loaders:
default:
filesystem:
bundle_resources:
enabled: true
access_control_type: blacklist
access_control_list:
- FooBundle // load from the first bundle path where the image is found
<img src="<?php $this['imagine']->filter('path/to/file.ext', 'my_filter_set') ?>" />
// load from a "MyCoolBundle" public bundle resource path explicitly
<img src="<?php $this['imagine']->filter('@MyCoolBundle:path/to/file.ext', 'my_filter_set') ?>" /> Support for symlink-friendly locator allows using symlink-heavy applications; using this locator disables symlink resolution on file paths and allows for symlink-deployed apps to function properly, at the expense of some security: liip_imagine:
loaders:
default:
filesystem:
locator: filesystem_insecure @ryancastle Is there something in our configuration missing for your environment? Otherwise, we'd be happy to review a PR adding useful functionality, or if your data loading requirements are extremely specific we support custom data loaders. Does this not meet the vast majority of requirements? :-) |
@robfrawley The insecure |
Providing the shared data path as an environment variable is a great idea. As for the locator changes, we became aware of security issues with our previous algorithm, so as of Also, be sure to reference the If you have any other questions be sure to reach out! We'll do our best to provide guidance. |
Hi y'all. The same problem over hereFORK CMS is using LiipImagineBundle in the MediaLibrary module. When deploying a Fork CMS website using Capistrano we have the same problem: A little more information about our modern setupIn the server root we have We have We have a symlink in every revision, f.e.: ConclusionSymlinks are being used, since that is a modern setup. |
This is the Fork CMS setup.
Working solution
And now allows symlinks. What didn't workChanging |
@jeroendesloovere The
As you've encountered, the following will not work, as your root contains symbolic links and these resolve outside the configured data root path: loaders:
# ...
default:
filesystem:
data_root: "/my/app/web/" What you can do (instead of changing the locator algorythm to loaders:
# ...
default:
filesystem:
data_root:
- "/my/app/web/" # this contains "foo" and "bar" symlinks
- "/data/foo" # the "foo" resolved symlink path
- "/data/bar" # the "bar" resolved symlink path The above multiple-data-roots example will accomplish the same thing as enabling the insecure filesystem locator, without degrading the security of the data loader operation: loaders:
# ...
default:
filesystem:
data_root: "/my/app/web/"
locator: filesystem_insecure # not recommended unless unavoidable Bonus Information: You can also utilize "named" data roots to enable selecting the correct root path when the same file exists in multiple roots. Let's assume the same directory structure (with the symbolic links) as detailed above. Now, assume you have a file loaders:
# ...
default:
filesystem:
data_root:
default: "/my/app/web/" # this contains "foo" and "bar" symlinks
foo: "/data/foo" # the "foo" resolved symlink path
bar: "/data/bar" # the "bar" resolved symlink path Once we've done this, we request our file (via the Twig extension or another API entry point) as you normally would, but instead use the notation Hope the above info help! We've been adding new features regularly, so the documentation for these new features (while it does exist) isn't verbose, clear, or readily advertised. If you have any questions, feel free to ask. And again, while |
I have one last comment for you. :-) I just noticed the above note you added to the end of your last post. While switching one for the other won't resolve your issue (as your data root changes and therefore so does all the paths you call your images from), instead you can add both and this will resolve your issue, without enabling loaders:
# ...
default:
filesystem:
data_root:
- "%kernel.project_dir%/"
- "%kernel.project_dir%/../" |
In pull request #775 a check is added so that the source file cannot be outside of the root path.
Our source files are loaded through a symlink, which is outside of the root path, and therefor I get the error message:
Source image invalid \"/home/data/uploads/article/someimage.png\" as it is outside of the defined root path
I can understand that it might improve security, but I think it is a pretty normal use-case to keep your uploaded images outside of the project root path (for back-up and autoscaling purposes)
Therefor I would suggest that there should be a configuration option to enable/disable this check, and then have it enabled by default.
The text was updated successfully, but these errors were encountered: