Skip to content
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

[Loader] Abstract filesystem resource locator and legacy insecure locator implementation #866

Merged
merged 1 commit into from
Feb 7, 2017

Conversation

robfrawley
Copy link
Collaborator

@robfrawley robfrawley commented Jan 31, 2017

Q A
Branch? 1.0
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #846
License MIT
Doc PR n/a

Abstract file locator, specifically FileSystemLocator and FileSystemInsecureLocator, outside of their respective "loader" classes to allow for multiple implementations of resource resolution. This includes an insecure resource locator version that allows symbolic links to be passed and blindly followed with no regard as to where they might point. This fixes environments that rely on deploy tools using symbolic links.

The question is, do we want to offer this functionality? @antoligy @cedricziel @davidromani

@lsmith77 lsmith77 added the State: Reviewing This item is being reviewed to determine if it should be accepted. label Jan 31, 2017
@robfrawley
Copy link
Collaborator Author

robfrawley commented Jan 31, 2017

Note that the FileSystemInsecureLocator is missing a comprehensive test suite; this will be added later if the consensus is to add this functionality. Additionally, this is a first-pass at tearing out file resource resolution from loaders, and will likely be refactored and cleaned up; right now we just need to figure out if this is something we should allow out-of-the-box.

@robfrawley robfrawley self-assigned this Jan 31, 2017
@robfrawley robfrawley changed the title Abstract resource location [WIP] [Loader] Abstract resource locator Jan 31, 2017
@robfrawley robfrawley added this to the 1.7.2 milestone Jan 31, 2017
@robfrawley robfrawley added Level: Enhancement ✨ This item involves an enhancement to existing functionality. State: Reviewing This item is being reviewed to determine if it should be accepted. and removed State: Reviewing This item is being reviewed to determine if it should be accepted. labels Jan 31, 2017
@robfrawley robfrawley force-pushed the feature-disable-realpath-checks branch 2 times, most recently from 61e9a1c to 5b47c80 Compare February 1, 2017 21:41
@robfrawley
Copy link
Collaborator Author

robfrawley commented Feb 3, 2017

Thoughts as to whether we want to offer a file locator (optional) implementation that is less secure, but allows symbolic links? @antoligy @cedricziel

$dataRoots
) {
$this->mimeTypeGuesser = $mimeTypeGuesser;
public function __construct(MimeTypeGuesserInterface $mimeGuesser, ExtensionGuesserInterface $extensionGuesser, $dataRoots, $secureLocator = true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth keeping this to multiple lines for readability?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough. I hate multi-line constructors (unless it's well past 120 characters). That said, I know many are big on it (and an 80 character line limit). I'll revert. ;-) 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind them so much if we could typehint on primitives... Grr... 😛

Copy link
Collaborator

@alexwilson alexwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good answer to this issue, without introducing too much complexity for future maintenance, so I'm happy with this!

@alexwilson
Copy link
Collaborator

My opinion is that it's worth adding the InsecureFileLoader, that way we can document that this practice is not recommended, without breaking existing deployments.

Happy for a test suite to appear in a future PR just so we can verify that this works, but I see it should function the same way as before we improved resolution.

@alexwilson
Copy link
Collaborator

Went ahead and resolved the conflict (loving that you can do this now!)- Janky commit but it should be resolved by a squash!

@robfrawley
Copy link
Collaborator Author

robfrawley commented Feb 6, 2017

@antoligy Thanks for the conflict resolution! Since you're on board with this approach, I'm gonna go ahead and add the tests to this PR tonight before merging (I don't like the idea of adding any new code without comprehensive tests ;-). Should we release 1.7.2 once this is merged? We have a decent amount of additions for a patch release, no? Or should we wait a bit?

@alexwilson
Copy link
Collaborator

Yeah that sounds like a good idea and I think so, as it addresses probably the only repeat complaint since 1.7.0 was released!

@robfrawley
Copy link
Collaborator Author

Right, sounds good. 👍 I'll get the tests implemented. Of note, I was just granted collaborator access to the avalanche123/Imagine repository today, so that should help us push items that effects this bundle upstream in the future.

@davidromani
Copy link

I think that it is a very good idea. FileSystemInsecureLocator can help me a lot, I prefer to release ASAP.

Thank you so much guys.

@robfrawley robfrawley force-pushed the feature-disable-realpath-checks branch from 3bcea00 to a2edd2e Compare February 7, 2017 01:04
@robfrawley
Copy link
Collaborator Author

robfrawley commented Feb 7, 2017

@antoligy Can you give this an additional once-over. I moved some stuff around, created a deprecation layer for FileSystemLoader::__construct() so we can change the method signature in 2.0, moved to services for FileSystemLocator implementations, refactored the locator classes a bit to remove as much duplication as possible, and changed the configuration to an enum value. Comprehensive tests have been implemented, as well.

@robfrawley robfrawley force-pushed the feature-disable-realpath-checks branch 3 times, most recently from e5e043f to 69952e1 Compare February 7, 2017 06:48
@robfrawley robfrawley force-pushed the feature-disable-realpath-checks branch from 69952e1 to f708b36 Compare February 7, 2017 06:58
@robfrawley robfrawley changed the title [WIP] [Loader] Abstract resource locator [WIP] [Loader] Abstract filesystem resource locator and legacy insecure locator implementation Feb 7, 2017
@robfrawley robfrawley mentioned this pull request Feb 7, 2017
@robfrawley
Copy link
Collaborator Author

@davidromani Before merging this, I'd like to confirm it does resolve your symbolic link issue. Can you patch your vendor release of this bundle with the PR and write back confirming proper functionality?

To apply this PR as a patch, you must perform the following:

# install the `master` from source
cd vendor/liip; rm -fr imagine-bundle
git clone https://github.com/liip/LiipImagineBundle.git imagine-bundle
cd imagine-bundle

# apply this PR as a patch
curl -L https://github.com/liip/LiipImagineBundle/pull/866.diff | patch -p1

# clear your cached assets
rm -fr web/path/to/cached/images/

Then enable the new filesystem_insecure locator by adding the following to your configuration:

liip_imagine :
  loaders:
    default:
      filesystem:
        locator: filesystem_insecure

@davidromani
Copy link

@robfrawley Yes, it works! Thank you so much!!

@robfrawley robfrawley merged commit d940443 into liip:1.0 Feb 7, 2017
@lsmith77 lsmith77 removed the State: Reviewing This item is being reviewed to determine if it should be accepted. label Feb 7, 2017
@robfrawley robfrawley changed the title [WIP] [Loader] Abstract filesystem resource locator and legacy insecure locator implementation [Loader] Abstract filesystem resource locator and legacy insecure locator implementation Feb 7, 2017
@alexwilson
Copy link
Collaborator

Nice work all! 🙂

@robfrawley
Copy link
Collaborator Author

robfrawley commented Feb 7, 2017

@davidromani The 1.7.2 release has just been published and you can immediately upgrade by calling composer via composer require liip/imagine-bundle:~1.7.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Level: Enhancement ✨ This item involves an enhancement to existing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants