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

Add a Signer Utility to sign filters, run php-cs-fixer on bundle #405

Merged
merged 31 commits into from
May 22, 2014
Merged

Add a Signer Utility to sign filters, run php-cs-fixer on bundle #405

merged 31 commits into from
May 22, 2014

Conversation

trsteel88
Copy link
Contributor

Closes #398

@makasim
Copy link
Collaborator

makasim commented Apr 23, 2014

@trsteel88 would it be possible to split the PR into two? cs fixes one and signer. That would be much easier to review.

@makasim makasim added this to the v1.0.0 milestone Apr 23, 2014
@makasim makasim self-assigned this Apr 23, 2014
@trsteel88
Copy link
Contributor Author

Is there a way I can split it without doing it manually?

@trsteel88
Copy link
Contributor Author

Also, how do you submit a separate PR on github. They all just go into my fork by the looks of it

@makasim
Copy link
Collaborator

makasim commented Apr 23, 2014

as far as I can see you can cherry pick d1fa795 commit to a new branch (based on master) and drop it from this branch while rebase -i

@trsteel88
Copy link
Contributor Author

Ok, that should be all good now.

@trsteel88
Copy link
Contributor Author

@makasim - I am going to take a crack at #399

I won't commit anything because I am going to use the new methods in this pull request. Any chance you can review this and merge?

@trsteel88
Copy link
Contributor Author

@makasim I decided to commit the fix for #399 here as it requires the SignerInterface.

It is all contained in 1 commit: a8b5c79

I am not quite sure why those 2 tests are failing. It doesn't seem to fail when I run them locally. The only thing I can think of is to commit with the hashes in the exception so I can see the output for testing. Are you able to take a look at the tests?

@makasim
Copy link
Collaborator

makasim commented Apr 24, 2014

Regarding #399. We can introduce new route for filters with runtime config. As you mentioned it can have prefix media/cache/rc. I wanted to split runtime filters to a separate action for a long time.

What do you think? As far as I can see the urls (filter and filter + runtime config) would never conflict.

@makasim
Copy link
Collaborator

makasim commented Apr 24, 2014

Regarding additionnal params in the url and broken sing. We definitly fix it before releaseing 1.0, It is bloker issue. Though I dont come up with a good solution. Introducing our own singer is not good idea IMO. I do not a security pro and therefor cannot maintain security issues. I would better rely on a good 3rd party library that does such job. Also the interface you introduced contains three parameters, it is looks like over kill. Could it be simplified? Maybe we can sing only filters parameters?

@trsteel88
Copy link
Contributor Author

I don't think we need the media/cache/rc because the filters parameter will be present and we can distinguish if it is a runtime config.

The code I used for the signer is the same code from the UriSigner for creating the hash.

We need to sign both the parameters and the path otherwise you could use the same hash on any image you would like which could be used as an attack.

@makasim
Copy link
Collaborator

makasim commented Apr 24, 2014

I don't think we need the media/cache/rc because the filters parameter will be present and we can distinguish if it is a runtime config.

yes we can, but the controller looks over loaded with the logic, just want keep it thin. Also two routings seems like easier and shorter fix for the #399 issue

@trsteel88
Copy link
Contributor Author

@makasim - I have just had a look at separating the controller into 2 actions.

This is a much bigger task than you think. It means that every single resolver is going to need to be passed the runtime config array so it can resolve it to the /media/cache/rc directory.

This will mean updating every single method in the resolves. eg resolve, isStore, store, remove.

Can I get this merged in and then we will tackle #399 separately?

@trsteel88
Copy link
Contributor Author

@makasim fyi, I have a project that needs to use this functionality which I need live by tomorrow. I would prefer not to override my composer using my fork so it would be much appreciated if I could get this through and tagged as alpha5

@makasim
Copy link
Collaborator

makasim commented Apr 28, 2014

nothing has to be changed in any resolvers, only CacheManager::getBrowserPath

@trsteel88
Copy link
Contributor Author

@makasim, that doesn't work. Check the controller. It uses the cacheManager to resolve the path which would redirect it to the non rc version

https://github.com/liip/LiipImagineBundle/blob/master/Controller/ImagineController.php#L98

I am thinking we can get rid of the $this->cacheManager->resolve($path, $filter) and just redirect to $request->getRequestUri().

This will also fix the issue with the query params being removed:

Query params should always stay on the image - Could be used for tracking/caching
It is especially important for runtime config images. If the cache is deleted and you refresh a runtime config request it means that the image can be re-resolved used the query params hash etc

@trsteel88
Copy link
Contributor Author

Ok I think that is it. However, I think it was more obvious what was happening previously with 1 controller action.

@trsteel88
Copy link
Contributor Author

Also, it still doesn't solve #399 because technically the user could still have 'rc/' in their url. It is unlikely though. If we wanted to solve it we could need to have /media/cache/normal/ and /media/cache/rc/ etc.

Honestly, I think we are better off merging before 2d60ee0 and having a single action and tackling #399 separately.

*/
public function trimHash($hash)
{
return substr(preg_replace('/[^a-zA-Z0-9-_]/', '', $hash), 0, 8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

move this logic to the controller. remove the method.

@makasim
Copy link
Collaborator

makasim commented May 9, 2014

@trsteel88 looks good to me, would you take care of the tests?

$binary = $this->dataManager->find($filter, $path);
} catch (NotLoadableException $e) {

throw new NotFoundHttpException('Source image could not be found', $e);
Copy link

Choose a reason for hiding this comment

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

Controller should throw NotFoundHttpException, not NotLoadableException.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

But it looks like you deleted this line, or I missed something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, you are right. I was looking at the wrong action. I will restore now.

@ama3ing
Copy link

ama3ing commented May 10, 2014

@trsteel88, do you think is this necessary to have full hash in url? I'd suggest to shorten it like github does to 7 symbols.

@trsteel88
Copy link
Contributor Author

@makasim asked me to use the entire string because he didn't like the trimHash method

Personally I was happy with the trimmed hash but I am at the point where I just need it merged.

@makasim
Copy link
Collaborator

makasim commented May 10, 2014

@Me1ifaro @trsteel88 I dont have anything against short hashes. We can use them. But in this case the sign method has to return a short one. We dont need a trim method.

@trsteel88
Copy link
Contributor Author

Ok, I'll make the entire hash 8 chars Monday morning.

@trsteel88
Copy link
Contributor Author

@makasim I can't work out why the tests are failing. It's like the runtime route isn't loaded into the tests. I can't find where this would be loaded though. Are you able to help?

@makasim
Copy link
Collaborator

makasim commented May 20, 2014

@trsteel88
Copy link
Contributor Author

That just has an include to

_liip_imagine:
resource: "@LiipImagineBundle/Resources/config/routing.xml"

Which includes https://github.com/trsteel88/LiipImagineBundle/blob/master/Resources/config/routing.xml
so it shouldn't be that?

@makasim
Copy link
Collaborator

makasim commented May 21, 2014

@trsteel88 I've fixed tests and did some small impr. Please review my PR https://github.com/trsteel88/LiipImagineBundle/pull/1

@trsteel88
Copy link
Contributor Author

Merged and we're passing @makasim :D

makasim added a commit that referenced this pull request May 22, 2014
Add a Signer Utility to sign filters, run php-cs-fixer on bundle
@makasim makasim merged commit b312ed3 into liip:master May 22, 2014
@makasim
Copy link
Collaborator

makasim commented May 22, 2014

and.... finally merged. Thanks for the critical fix @trsteel88 and your unbelievable patients.

You did that! Congrats.

Tagging as 1.0.0-alpha7 (thinking of beta now).

@trsteel88
Copy link
Contributor Author

No worries. Thanks for helping with those tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Attn: Blocker This item blocks other issue(s) or PR(s) and therefore must be resolved prior. Level: Bug 🐞 This item involves a legitimate regression (bug) to existing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Url Signer
4 participants