Problem/Motivation

_locale_parse_js_file() throws an exception if an external file is passed in, but I can't see anywhere in the call path (locale_js_alter() -> locale_js_translate() where those are supposed to be filtered out.

This makes it impossible to add external JS files on a non-en site.

As a workaround, you can specifiy a protocol-agnostic URL (//example.org/file.js), but that just gets you around that check, I have no idea what actually happens then.

I also have no idea what exactly caused this?

Proposed resolution

Filter out external JS files.

Remaining tasks

User interface changes

API changes

Comments

gábor hojtsy’s picture

This was added in http://cgit.drupalcode.org/drupal/diff/?id=733f68f17f0f227d0f970bc412177..., looks like the interaction with JS alter was not considered.

berdir’s picture

berdir’s picture

Status: Active » Needs review
Issue tags: +Needs tests, +Needs backport to 7.x
StatusFileSize
new615 bytes

Here's a very simple patch that filters out external files, I think it is perfectly valid to never attempt to translate them.

Based on the referenced issue and the history, the code is exactly the same as in 7.x, just that we now throw an exception, so before that, we just parsed those external files.

This should also fix #1814980: file_get_contents is used on remote URIs in locale.inc, which is currently trying weird workarounds to load those external files.

berdir’s picture

Issue summary: View changes
gábor hojtsy’s picture

Makes sense IMHO.

Status: Needs review » Needs work

The last submitted patch, 3: locale-js-alter-ignore-external-2385069-3.patch, failed testing.

xjm’s picture

Issue tags: -Needs backport to 7.x +Needs backport to D7
nlisgo’s picture

Issue tags: +Needs reroll
nlisgo’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new810 bytes
jhedstrom’s picture

StatusFileSize
new1.14 KB

I tried writing a test for this, but since common_test.libraries.yml defines the external files as type: external, this test passes. So from what I can tell, that is perhaps an undocumented workaround?

catch’s picture

David_Rothstein’s picture

I tried writing a test for this, but since common_test.libraries.yml defines the external files as type: external, this test passes. So from what I can tell, that is perhaps an undocumented workaround?

Rather than an undocumented workaround, isn't it actually the expected way for external files to be loaded?

In other words, it's not immediately obvious to me what the core bug is here; locale_js_alter only calls locale_js_translate()=>_locale_parse_js_file() for JavaScript of type 'file', not for type 'external'.

Doesn't that mean this problem only occurs if there is calling code out there that incorrectly uses 'file' for an external JavaScript file, when it should have used 'external' instead?

I also marked #1814980: file_get_contents is used on remote URIs in locale.inc as a duplicate.

gboddin’s picture

Hello all, I said on https://www.drupal.org/node/1814980 :

@David_Rothstein

This can be a security risk :

Imagine a user has a role in the backend that is able to feed javascript file/uri to add_js trough wathever module.

He can just request resources that wouldn't be touchable otherwise because it bypass the proxy.

I agree it requires some pre-configuration that might not be common to all users, but it's still possible to :

- Either get content from network resources that you shouldn't
- Trigger actions on a network resource that you shouldn't

Even if tiny, this is a risk, people usually use proxies in their app to avoid it using direct connections to external AND internal resources

Regards.

gboddin’s picture

Just read :

In other words, it's not immediately obvious to me what the core bug is here; locale_js_alter only calls locale_js_translate()=>_locale_parse_js_file() for JavaScript of type 'file', not for type 'external'.

------------------------

This makes total sense to me now, yes, and indeed we had only one bad sheep ( using add_js() wrong , without specifying external )

Not sure then if a simple check could be added to avoid it from happening as I feel some contrib modules might be bad sheeps in this regards as well.

Maybe the methods needing filtering are add_js and add_css in this case !

David_Rothstein’s picture

This can be a security risk :

Imagine a user has a role in the backend that is able to feed javascript file/uri to add_js trough wathever module.

He can just request resources that wouldn't be touchable otherwise because it bypass the proxy.

I guess I see your point, but if an untrusted user can add arbitrary JavaScript files to the site, they can already do a cross-site-scripting attack against any other user... it seems like that would tend to be a much bigger concern.

gboddin’s picture

I see your point, but I think it depends of the perspective and the size of the webmaster/dev team.

I'll try to clarifiy the example :

In our environment, we tend to decouple those responsabilities to developers, while all the network and proxy constraint are done at the sysadmin level.

In my point of view ( sysadmin ), I cannot check 100 sites for bad usage when developers allow customers to include JS (we have QA for that, but QA process can go wrong, they can miss it, not think about it, or include a contrib modules wrongly using add_js / add_css).

I can however "make sure" that they won't touch the infrastructure as much as possible by providing a solid core that won't allow them to make direct network queries (we forbid anything not HTTP and force dev to use drupal_http_request).

Again, I agree it's blurry, but I would say it can improve (but also break) a lot of contrib module security, I also admit it requires a lot of conditions to be exploitable.

gboddin’s picture

( if it can help, here's a commit to (temporarly) fix the issue on our side and get notified of bad practices )

https://github.com/ec-europa/platform-dev/pull/414/commits/981a961b7dc00...

pfrenssen’s picture

StatusFileSize
new601 bytes

This is how the patch from #10 would look on Drupal 7. @gboddin, can you check if this would suit your needs? It does not include the logging you currently have in your proposed patch, but this will not be acceptable in a core patch anyway. I have no tested this by the way. It's just a straight port of the patch.

About the security risk, what I think you mean is this: you are managing 100+ websites which are allowing developers and site builders to include locally sourced javascript files in their websites. These local javascript files have been checked for potential security issues by the QA team. External files are considered a security risk since they have not been validated by the security team and can contain potential attack vectors. Is that a good description?

If this is the case then I agree this is a security issue from your devops perspective, but it would not affect a typical Drupal website since which has full control over the JS files they include since they come from a trusted source: the developer of the website. So from Drupal's point of view this is not a security issue. It depends how much you trust your developers :)

gboddin’s picture

@pfrenssen , Actually I'm thinking more about contrib modules.

But as David_Rothstein said, it's the module not using drupal_add_js properly.

I opened https://www.drupal.org/node/2697611 and proposed a patch for drupal_add_js method.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tuwebo’s picture

StatusFileSize
new713 bytes

Patch relloled, just updated for last version.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative, +Needs issue summary update

When we moved to libraries did we circumvent this issue or is it still possible to declare an external JavaScript library with type file?

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

heddn’s picture

Status: Postponed (maintainer needs more info) » Needs review
Related issues: +#2735717: Stream wrapper reference in JS library causes error in _locale_parse_js_file()
anchal_gupta’s picture

StatusFileSize
new719 bytes

Rerolled patch against 9.4X

larowlan’s picture

Status: Needs review » Postponed (maintainer needs more info)

Is this a duplicate of #2735717: Stream wrapper reference in JS library causes error in _locale_parse_js_file()? Can you test this issue with the patch from over there applied?

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

smustgrave’s picture

Following up if anyone was able to verify #36 if so we can close this out and move over credit.

heddn’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Yes, this is a duplicate. Closing