Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
https://github.com/drupal-media/media_entity_twitter/pull/24
This will knock your socks off.
Comment | File | Size | Author |
---|---|---|---|
#24 | interdiff.txt | 998 bytes | slashrsm |
#24 | 2650976_24.patch | 26.25 KB | slashrsm |
#23 | interdiff-2650976-21-23.txt | 1010 bytes | phenaproxima |
#23 | 2650976-23.patch | 26.25 KB | phenaproxima |
| |||
#21 | interdiff-2650976-19-21.txt | 589 bytes | phenaproxima |
Comments
Comment #2
slashrsm CreditAttribution: slashrsm as a volunteer commentedThis looks amazing indeed! Just two nitpiks.
Comment #3
slashrsm CreditAttribution: slashrsm as a volunteer commentedComment #4
phenaproximaOkay, I have finally come back to this and rolled a patch :) It could probably use a test or two, but I'd like to have the implementation OKed first before I do that.
Comment #5
phenaproximaI was having trouble getting user avatars to be embedded directly in the tweet thumbnails -- this is now fixed.
Comment #6
samuel.mortensonSome review:
Would this make an external request every time the preprocess function is called? I'm guessing that once the SVG is generated this will never be called again, so that might be OK. Just checking!
Due to security paranoia, it might be good to hard-core the image extension if we know what to expect from Twitter. For example, if the extension of the avatar is SVG, that SVG could contact executable code.
I also mentioned at NYCCamp that there is a fair use concern with making copies of Tweets. You can read Twitter's article on this here: https://support.twitter.com/articles/20171959. The TL;DR (IANAL) of the liability is that if I make a Tweet and you make a copy of it on your site that violates Fair Use, I can file a complaint against Twitter and might get your API access revoked. This sounds scary, but if these thumbnails are only displayed in the backend it's unlikely that you are going to get complaints filed against you (unless your content editors created a Tweet you've embedded). Even if a complaint does get filed against your account, if you're only using this in an admin interface (i.e. the thumbnails are not publicly accessible), you are probably fine.
Comment #7
phenaproximaThe request is only made when the SVG is generated. From then on, the avatar is wholly embedded in the generated SVG and never needs to be downloaded again.
We don't know what to expect from Twitter, so we cannot hard-code the extension. I'm pretty sure Twitter does not allow SVGs in avatars, but if we want to err on the side of paranoia, we could probably validate the extension before the SVG is generated and ensure that it's gif, jpe?g, png, or webp. And if it is none of those extensions, omit the avatar from the generated thumbnail. That seems like a fair compromise to me.
Fair use is a tricky one. Obviously we cannot guarantee that people won't trample all over Twitter's fair use policy, so I suggest that we add a checkbox to the Twitter media type plugin's configuration that specifically enables the auto-generation of thumbnails. The checkbox could have an explanation about the risks (and a link to Twitter's policies) in its description. So that way, at least people would be informed about the hornets' nest they are potentially kicking. Drink responsibly.
Comment #8
samuel.mortensonYep, that would work for me. The specific exploits I can think of are 1) Embedding SVGs with untrusted data 2) Malformed extensions that could break out of the tag. I guess that we should trust Twitter to validate extensions, but the more checks we can do, the better!
That, or any explicit documentation should be fine. I'm not sure how to properly warn users when enabling a module, so a check box makes sense since they have to interact with it.
Comment #9
phenaproximaImplemented both ideas.
Comment #11
phenaproximaSigh. Forgot to update config schema.
Comment #12
phenaproximaAfter a quick discussion in the #drupal-media IRC channel, it was decided that this is really hard to test as long as the ability to fetch tweets from Twitter's API is not wrapped by a service (this functionality, after all, does not work without the Twitter API). To that end, I've moved the tweet-fetching stuff into its own service, the TweetFetcher.
Comment #13
mtodor CreditAttribution: mtodor at Thunder commentedA bit tricky to test. Here are few ideas that maybe can help.
Comment #14
phenaproximaOkay, I wrote a test. It's not the most extensive coverage in the world but it should at least verify that thumbnails are generated when they should be. Every new code path I added in this patch (except for the preprocess function) is tested here.
Comment #15
phenaproximaFixed an invalid URL in TweetFetcher::fetchTweet() -- this would never be catchable in the tests because it would only show up when using Twitter's real API -- and added the Twitter logo as a background to the generated thumbnails. Sorry about the extra cruft in the interdiff; that's the result of re-rolling this patch against HEAD following typo fixes.
Comment #17
phenaproximaOkay, here is the actual patch without any cruft from 8.x-1.x in it. Sometimes I rock at git, and other times it eats me for lunch.
Comment #18
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedFinally managed to look at this. Looks great. I have a few comments, but we should be almost there. Great work!
$image_url is not the actual data... Yes, if this is broken then it is an existing bug, but would be nice to fix it anyway.
Class docblock missing.
$this->twitter
may not be initialized at this point.Any ideas for checks? If they are straightforward could we add then now?
Set a lifetime?
Would be nice to have custom exception class.
Description missing.
It seems that this assumes entity id. Is it safe to do that (usually not)?
Let's do that :)
Comment #19
phenaproximaAll fixed, except #8.
That's a tweet ID, not an entity ID. I just didn't think I needed to bother with a 20-digit number in the test ;)
Comment #21
phenaproximaMan. Rename one little service, get smote by the testing gods. The life of a programmer is fraught with peril.
Comment #23
phenaproximaOkay, testbot, you wanna play rough? Let's play.
Comment #24
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedFixed a nitpik. Should be ready to go.
Comment #26
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedComment #28
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commented