Ref T4190. Currently only have the endpoint and controller working. I added caching so subsequent attempts to proxy the same image should result in the same redirect URL. Still need to:
- Write a remarkup rule that uses the endpoint
Differential D16581
Endpoint+controller for a remarkup image proxy jcox on Sep 21 2016, 2:02 PM. Authored by Tags None Referenced Files
Subscribers
Details
Ref T4190. Currently only have the endpoint and controller working. I added caching so subsequent attempts to proxy the same image should result in the same redirect URL. Still need to:
Hit /file/imageproxy/?uri=http://i.imgur.com/nTvVrYN.jpg and are served the picture
Diff Detail
Event TimelineComment Actions Looks good so far. I think the cache needs to be slightly more complicated than this -- I'll expand in T4190.
Comment Actions Added a cache storage table so we can clean up the cache. Comment Actions Some minor feedback, but mostly stylistic stuff. Tackle whatever makes sense; we can always revisit things later.
Comment Actions Ah. execute() and executeOne() mostly do what you might expect (return a list vs return a single result), but have slightly different behavior when results aren't visible to the viewer:
This mostly corresponds to the default behavior on a page like /T123 (show the user a policy exception) vs a page like /maniphest/ (don't list tasks the user can't see). Occasionally code will do execute() + head($results) to dodge policy exceptions or do other sketchy/unusual things. (This behavior can be adjusted with setShouldRaisePolicyExceptions(...) on the Query object.) Comment Actions Cool, this looks good to me. I'll write up a little guidance on the remarkup rule.
Comment Actions I'd probably just throw and we can deal with it if/when it ever occurs in the wild. I can't come up with any way that we'd actually end up in this state. I could imagine deleting the request possibly leading to some weird loop where we have a bug with loading the file, causing us to fetch and delete it over and over again. This could happen anyway and the rate limiting would stop it, but trying to recover here might make it slightly more likely. This is pretty weak reasoning but the best argument I can come up with one way or the other. I think there's also a minor permissions improvement we can make: right now, I think users other than the first user to request the file won't actually be able to see it: the policy gets set to "No One" + specific author, which means "Only That User". Two things here: first, the authorPHID itself. I think we probably should not set the authorPHID, since it's not necessarily the actual "author" in any real sense -- it's just the first person to fill the cache. This information feels like a little bit of a policy leak to me, not correct behavior for this request cache. We could fix this by either not setting the authorPHID at all, or setting it to the Files application PHID. Second, the actual policy issue. We could set the file policy to "Public", but that would make the file listable in the file list at /file/. This seems slightly wrong -- if you know the URI you should be able to see the file, but if you don't know the URI you probably shouldn't be able to discover all the URIs that users are embedding anywhere. For now, I think it's probably better to leave the policy at POLICY_NOONE, not set authorPHID(), and use PhabricatorUser::getOmnipotentUser() as the $viewer when querying for the file in getExternalResponse() to bypass policies. We know it's OK to bypass policies on the file since we looked up the PHID on an ExternalRequest, so the file isn't private/secret. I think that should give us reasonable behavior for now.
|