Problem/Motivation

This issue is spun off from the pile-on happening in #2965979: Validate alternate domain for oEmbed iFrame.

When the oEmbed system was added to the core Media module, one of the protections added against malicious JavaScript was the suggestion that site owners configure their Drupal site to be visible through a subdomain alias (basically, oembed.example.com == example.com) so that malicious JavaScript served from an oEmbed provider would have an additional hoop to jump through. We felt strongly enough about this measure that, if oEmbed content is not served in a subdomain, we display a warning on the status report page.

However, this is tricky to set up -- it's poorly documented and the warning drives site builders crazy (as evidenced by discussion in #2965979: Validate alternate domain for oEmbed iFrame) until they get it set up properly. And even when they do, it's not clear that there is actually a security improvement here.

  1. If a subdomain is used, browsers consider it to be part of the main site, so it can share cookies with the main domain.
  2. If a completely different domain is used instead of a subdomain, users can go directly to the second domain, which, because it is the same Drupal site, is configured to use itself as the iFrame domain.

The oEmbed specification recommends that the HTML within the iFrame be hosted on another domain. The intention is for the HTML within the iFrame to be entirely separate from the main site. It does not recommend using a subdomain, or that the entire site be accessible from the other domain.

Steps to reproduce

Install the Standard profile and the Media module, then visit the status report page.

Proposed resolution

Quick fix

Given that the full fix is complex and will take some time to develop, I [AdamPS] propose that ASAP we could remove the existing warning. It has likely wasted 1000s of hours of site builder and developer time trying to follow the instructions, which a low likelihood of actually providing anyone with any protection at all. It's so complex to do correctly and lacking in accurate full documentation that I doubt even 1% of those who try do it succeed; they might even introduce security bugs by doing it incorrectly.

Full fix

  1. In the iFrame domain only serve pages that should be used there. Block these pages in the main domain. If there is not an iFrame domain, use a data URL and sandbox attribute to minimize the possibility of cookies leaking into the iFrame.
  2. Automatically set same-origin policy so that the embedding actually works
  3. Don't allow the iFrame domain to be a sub-domain of the main domain OR find a way to set a cookie policy so that the sub-domain cannot share cookies with the main domain
  4. Treat the iFrame domain as trusted specifically for the pages that it should serve without needing to set it in the list of trusted hosts
  5. Provide a way to disable the warning given that the site is still reasonably secure without the extra domain and not everyone will want to purchase an extra domain.
  6. Provide detailed documentation for site builders.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

Comments

phenaproxima created an issue. See original summary.

longwave’s picture

The suggestion of an alternate domain is taken from the oEmbed spec: https://oembed.com/#section3

When a consumer displays HTML (as with video embeds), there's a vector for XSS attacks from the provider. To avoid this, it is recommended that consumers display the HTML in an iframe, hosted from another domain. This ensures that the HTML cannot access cookies from the consumer domain.

However I agree that this is a huge technical hurdle for most sites to implement.

darren oh’s picture

Issue summary: View changes

Pointing the alternate domain at the same site makes the security benefit questionable.

phenaproxima’s picture

Issue tags: +Needs security review

Tagging this to be reviewed by a member of the security team. To be succinct, this is what we need to know...

First, are these points from the issue summary accurate? Because if they are, it would seem that it's pointless to have a warning on the status report asking site owners to set up a subdomain alias:

If a subdomain is used, browsers consider it to be part of the main site, so it shares cookies with the main domain.
If a completely different domain is used instead of a subdomain, users can go directly to the second domain, which, because it is the same Drupal site, is configured to use itself as the iFrame domain.

Second, should we implement one or both of the following mitigations? If we did, could we remove the warning from the status report?

Do not allow login from the iFrame domain. If there is not an iFrame domain, use a data URL and sandbox attribute to minimize the possibility of cookies leaking into the iFrame.

larowlan’s picture

From the oembed docs:
> When a consumer displays HTML (as with video embeds), there's a vector for XSS attacks from the provider

And then from the Cookie docs here

The Domain attribute specifies which hosts are allowed to receive the cookie. If unspecified, it defaults to the same host that set the cookie, excluding subdomains. If Domain is specified, then subdomains are always included. Therefore, specifying Domain is less restrictive than omitting it. However, it can be helpful when subdomains need to share information about a user.

For example, if Domain=mozilla.org is set, then cookies are available on subdomains like developer.mozilla.org.

So in summary it depends on the cookie domain - can we check if the cookie domain is set, and if it is, then we need to show a different warning.

For image styles we have a 'disable secure image generation' settings.php thing. I guess we could do the same here

$settings['media.accept_insecure_iframe_domain'] to turn this off.

darren oh’s picture

I'm not sure that every browser follows the Mozilla cookie policy when the domain attribute is omitted.

darren oh’s picture

Issue summary: View changes

Corrected description of security concern to account for Mozilla cookie policy.

larowlan’s picture

For clarity, that's not the Mozilla cookie policy, its from MDN, which is a generic documentation site

larowlan’s picture

See https://tools.ietf.org/html/rfc6265#section-5.1.3 for the RFC about domain name matching

darren oh’s picture

Section of RFC discussing what happens if domain attribute is omitted: https://tools.ietf.org/html/rfc6265#section-4.1.2.3

darren oh’s picture

Issue summary: View changes

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

fkelly12054@gmail.com’s picture

How about for simple sites the ability to just turn off OEMBED? Or does that make using the media module pointless?

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.

it-cru’s picture

As 3. point in proposed resolution also avoid display of duplicate content of your Drupal site is a very critical SEO related issue, when settings this up in a right way.

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.

adamps’s picture

Priority: Normal » Major
Issue summary: View changes

I've made two edits that I would appreciate comments/feedback on from the community:

1) I propose that ASAP we should remove the existing warning. It has likely wasted 1000s of hours of site builder and developer time trying to follow the instructions, which a very low likelihood of actually providing anyone with any protection at all. It's so complex to do correctly and so lacking in documentation that I doubt even 1% of those who try do it succeed; they might even introduce security bugs by doing it incorrectly.

2) I have expanded the proposed resolution to automatically take care of as many aspects of the solution as possible to give site builders the best possible chance of getting it working.

tunic’s picture

Feedback on #19:

1) I fully agree removing the warning. I spent hours myself trying to solve that warning without luck.

2) Full fix description sounds reasonable sounds reasonable but I don't know all the nuances of cookie behavior so I can't have a strong opinion.

pameeela’s picture

Discovered this issue while looking into this warning, which I have seen and ignored hundreds of times, in light of Starshot.

After reading through this and #2965979: Validate alternate domain for oEmbed iFrame I totally agree that the warning should be removed given that 1) it's extremely difficult to implement and 2) of dubious value. I understand that it's a recommendation but as it stands this feels like Drupal saying "This is a potential thing that you should maybe worry about, and we can't help you but we told you so now it's on you". In other words, very un-Drupal!

What do we need to do to get a decision on this?

longwave’s picture

Status: Active » Needs review
Issue tags: +Barcelona2024

Discussed with @xjm at Drupalcon Barcelona. As this policy needs review, I'm marking this needs review - so far we haven't heard any opposing voices that want to keep this feature, but I will raise this with the rest of the security team and give them chance to comment here.

ivnish’s picture

I propose that ASAP we should remove the existing warning too. +1

krakenbite’s picture

+1 too. Please remove it

marcoscano’s picture

+1 for removing. Folks that know how to fix it probably don't need the reminder.

mxr576’s picture

The outcome of this issue could make the following one "closed, won't fix".

longwave’s picture

Issue tags: -Needs security review

I discussed this issue with @mcdruid. Some notes from the discussion:

  • Injected JavaScript cannot steal session cookies if the httpOnly flag is correctly applied to those cookies which mitigates some possible attacks.
  • It is possible to harden iframes with the sandbox attribute, which WordPress apparently does: https://core.trac.wordpress.org/ticket/44400 - however this may break existing embeds in some cases so will require testing.
  • Credentialless iframes look like a possible future solution, but they are not yet supported in Firefox or Safari.

We agreed that this could be broken into three issues:

  1. Remove the warning message, given the difficulty to implement the suggestion and the lack of documentation on how to actually do it.
  2. Experiment with adding the sandbox attribute to the OEmbed iframe
  3. If #2 succeeds, remove the alternate domain setting
pameeela’s picture

Status: Needs review » Reviewed & tested by the community

Was reminded of this today and decided to try to move it along. Updated #2962753: Remove oEmbed security warning to be about removing the warning as the first step in #27.

I think this policy issue can be fixed?

martijn de wit’s picture

Maybe we can convert this issue to a meta ticket holding all suggested child tickets?

pameeela’s picture

Since this is a policy issue, I think it should be marked fixed once the policy is agreed. It should be referenced in the follow up issues.

pameeela’s picture

Created a follow up for the sandbox experimentation.

pameeela’s picture

pameeela credited lauriii.

pameeela’s picture

Credited everyone who contributed to this issue (beyond just saying +1) and @lauriii for discussion in person in Singapore.

pameeela’s picture

Issue tags: +Singapore2024
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

longwave credited mcdruid.

longwave’s picture

Adding credit for @mcdruid for discussing with me and raising some of the points mentioned in #27.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

Adding credit for myself as per #22. Remember to credit in-person discussions, folks. :)

quietone’s picture

Changing to latest version when this was closed.

quietone’s picture

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