Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($compile): turn link[href] into a RESOURCE_URL context. #14687

Closed
wants to merge 1 commit into from

Conversation

rjamet
Copy link
Contributor

@rjamet rjamet commented May 27, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix.

What is the current behavior? (You can also link to an open issue here)

There's no $sce context for link[href], meaning a tag will have no $sce protection (might have link sanitization though, I'm not sure of that). That's fine for several rel types, but at least stylesheet and import can run script in your origin, which corresponds to a RESOURCE_URL context.

What is the new behavior (if this is a feature change)?

Turn it into a RESOURCE_URL context. Note that this is an overcorrection, sadly, but the security level of this attribute depends on the rel attribute, and I don't know if we can make context-aware decisions in this type of situation.

RESOURCE_URLs are allowed to be interpolated if the value is $sce-blessed, or for plain strings if they're from the same origin.

Angular2 is being fixed to do the same with https://github.com/angular/angular/pull/8869/files#diff-5ffbf51559339aaa2db503c37cc3a658R60.

Does this PR introduce a breaking change?

Most apps keep the default whitelist, so it will break apps with dynamically-set link[href]s pointing to other origins.

Please check if the PR fulfills these requirements

No comprehensive list of contexts in the docs to update, they just say the $sce.RESOURCE_URL type is "For URLs that are not only safe to follow as links, but whose contents are also safe to include in your application. Examples include ... ".

For now, there's no security in there, so a dynamic href has no protections
against evil stylesheets. It shouldn't be a common pattern anyways, but an
user-controlled import or stylesheet (and serviceworkers seem to be in the
works too) can run script in your origin, which warrants the RESOURCE_URL
context.
@petebacondarwin
Copy link
Contributor

@mprobst can you give a view on this - since you are working on the A2 version?

@mprobst
Copy link
Contributor

mprobst commented May 27, 2016

Yes, this is correct. Thanks for the fix Raphael!

@gkalpak
Copy link
Member

gkalpak commented Jun 3, 2016

Isn't this a BC ?

@mprobst
Copy link
Contributor

mprobst commented Jun 3, 2016

This is a breaking change. LGTMs though.

@gkalpak
Copy link
Member

gkalpak commented Jun 3, 2016

LGTM2 - I'm just saying we should update the commit message with a BC notice (including instructions on how to update old code).

gkalpak pushed a commit that referenced this pull request Jul 20, 2016
User-controlled imports or stylesheets can run script in your origin,
which warrants that we require that they are safe `RESOURCE_URL`s.

Closes #14687

BREAKING CHANGE

`link[href]` attributes are now protected via `$sce`, which prevents interpolated
values that fail the `RESOURCE_URL` context tests from being used in interpolation.

For example if the application is running at `https://docs.angularjs.org` then the
following will fail:

```
<link href="{{ 'http://mydomain.org/unsafe.css' }}" rel="stylesheet">
```

By default, `RESOURCE_URL` safe URLs are only allowed from the same domain and protocol
as the application document.

To use URLs from other domains and/or protocols, you may either whitelist them or
wrap it into a trusted value by calling `$sce.trustAsResourceUrl(url)`.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants