Problem/Motivation

In #3080666-74: oEmbed system doesn't work if thumbnail url does not have a file extension, @b_sharpe raised the point that the oEmbed system, when retrieving the thumbnail for a resource, does not do any kind of control of what the extension is. A provider could theoretically return a file with a .php extension, containing actual PHP code, and it would be saved into the filesystem.

Now, as far as I know, it never actually be executed by the PHP interpreter; instead, it would be fed into the image toolkit, which would probably choke on it. So I don't think this is an actual exploitable security issue, but it's certainly a thing we could harden.

Steps to reproduce

N/A; this is a theoretical case.

Proposed resolution

The oEmbed source plugin should try to validate that the downloaded thumbnail is, in fact, an image, by both limiting the thumbnail filename to valid image extension and also using the image toolkit to confirm that the downloaded image data is truly a valid image.

Remaining tasks

None

User interface changes

None.

API changes

TBD, but likely none.

Data model changes

None.

Release notes snippet

TBD

Issue fork drupal-3223012

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Issue summary: View changes
cilefen’s picture

Would the MimeTypeGuesser be more lightweight and simpler?

phenaproxima’s picture

Well, we're already leveraging the MimeTypeGuesser in #3080666: oEmbed system doesn't work if thumbnail url does not have a file extension. But I'm not sure if that does the kind of deeper validation (i.e., does this really work with the image toolkit, or does it merely say it does?) that I'm talking about in this issue.

cilefen’s picture

^ that issue seems to use the extension list, which is different than the guesser but I understand your point.

b_sharpe’s picture

I'd be curious to know if even if the image toolkit can't read the file if it is indeed saved to the likely public file system, IF (and I'm assuming with oEmbed this is a pretty big IF) said provider returned a malicious file that it might somehow be able to execute the file, I'm guessing not given the file is hashed as well, but this was where the original concern came from for context.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

longwave made their first commit to this issue’s fork.

longwave’s picture

Category: Feature request » Task
Status: Active » Needs review
smustgrave’s picture

Left comments and a question on the MR.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Sorry this fell off my radar. Thanks for answering the question.

longwave’s picture

Issue summary: View changes

Updated the IS with the current solution.

  • catch committed 9020953b on 11.5.x
    task: #3223012 oEmbed system should validate that downloaded thumbnails...

  • catch committed a7a5261a on 11.x
    task: #3223012 oEmbed system should validate that downloaded thumbnails...

  • catch committed 7e952a76 on 12.0.x
    task: #3223012 oEmbed system should validate that downloaded thumbnails...

  • catch committed 89973d2d on main
    task: #3223012 oEmbed system should validate that downloaded thumbnails...
catch’s picture

Version: main » 11.4.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed main, 12.0.x, 11.x and 11.5.x, thanks!

I made a suggestion in the MR to bump the deprecation to 11.5, but then forgot to apply it before committing.

But then I wondered whether we should backport this to 11.4.x after all since it's security hardening, so moving to 'to be ported' to discuss. We've mostly stopped 11.4 backports at this point but this is in the category of things we still might.

longwave’s picture

Status: Patch (to be ported) » Needs work
Issue tags: +Needs change record

Also the deprecation notice links to a non-existent nid, so we should write the change record and update that!

catch’s picture

It's only a constructor deprecation, so I wouldn't write a change record, but yes we should link back to this issue instead of 9999999, was too busy looking at the version.