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

Consider base URL when deciding if a URL is allowed by 'self' URL policy #15144

Closed
adob opened this issue Sep 15, 2016 · 4 comments
Closed

Consider base URL when deciding if a URL is allowed by 'self' URL policy #15144

adob opened this issue Sep 15, 2016 · 4 comments

Comments

@adob
Copy link
Contributor

adob commented Sep 15, 2016

Angular SCE currently rejects perfectly valid relative URLs in some situations when a tag is used. For example, if the page contains <base href="http://www.example.com">, Angular will start to reject relative URLs like 'foo.template.html'. Full example at https://plnkr.co/edit/3sFwq1d2d7wiWVBx4OHn

The root cause is that the urlIsSameOrigin() function in urlUtils.js matches against location.href instead of, or in addition to, document.baseURI.

Angular should permit URLs if protocol/host/port matches the base URL being used.

Affects AngularJS v1.5.8.

@gkalpak
Copy link
Member

gkalpak commented Sep 19, 2016

Sounds reasonable, although I am not aware of any security implications.

/cc @rjamet, @mprobst

@rjamet
Copy link
Contributor

rjamet commented Sep 21, 2016

Sounds good to me too, a base href is a sign that the destination is trusted, that's in line with the same-origin whitelist.

(Small caveat, base href doesn't seem to require a RESOURCE_URL to be set in bindings, and I'm not entirely sure whether it affects things that can run scripts, like script src. If it does affect these, it definitely should be a RESOURCE_URL context. I'll write a PR.)

@gkalpak
Copy link
Member

gkalpak commented Sep 21, 2016

Maybe it is indeed a good idea to also sanitize href for <base> elements, e.g. here.

@rjamet
Copy link
Contributor

rjamet commented Sep 21, 2016

That's implicit in the resource url contract: the default whitelist won't allow different protocols than the current page, and that's also why a resource_url is valid in URL context.

I don't really know how weird things like base href="data:text/html" behave (at least this hasn't executed javascript: URLs in a while), but you'd have to whitelist them first for it to work. I'll run some tests before the end of the week and write a PR at least for the context thing.

gkalpak pushed a commit that referenced this issue Jan 10, 2017
Page authors can use the `<base>` tag in HTML to specify URL to use as a base
when resovling relative URLs. This can cause SCE to reject relative URLs on the
page, because they fail the same-origin test.

To improve compatibility with the `<base>` tag, this commit changes the logic
for matching URLs to the 'self' policy to allow URLs that match the protocol and
domain of the base URL in addition to URLs that match the loading origin.

**Security Note:**
If an attacker can inject a `<base>` tag into the page, they can circumvent SCE
protections. However, injecting a `<base>` tag typically requires the ability to
inject arbitrary HTML into the page, which is a more serious vulnerabilty than
bypassing SCE.

Fixes #15144

Closes #15145
gkalpak pushed a commit that referenced this issue Jan 10, 2017
Page authors can use the `<base>` tag in HTML to specify URL to use as a base
when resovling relative URLs. This can cause SCE to reject relative URLs on the
page, because they fail the same-origin test.

To improve compatibility with the `<base>` tag, this commit changes the logic
for matching URLs to the 'self' policy to allow URLs that match the protocol and
domain of the base URL in addition to URLs that match the loading origin.

**Security Note:**
If an attacker can inject a `<base>` tag into the page, they can circumvent SCE
protections. However, injecting a `<base>` tag typically requires the ability to
inject arbitrary HTML into the page, which is a more serious vulnerabilty than
bypassing SCE.

Fixes #15144

Closes #15145
ellimist pushed a commit to ellimist/angular.js that referenced this issue Mar 15, 2017
Page authors can use the `<base>` tag in HTML to specify URL to use as a base
when resovling relative URLs. This can cause SCE to reject relative URLs on the
page, because they fail the same-origin test.

To improve compatibility with the `<base>` tag, this commit changes the logic
for matching URLs to the 'self' policy to allow URLs that match the protocol and
domain of the base URL in addition to URLs that match the loading origin.

**Security Note:**
If an attacker can inject a `<base>` tag into the page, they can circumvent SCE
protections. However, injecting a `<base>` tag typically requires the ability to
inject arbitrary HTML into the page, which is a more serious vulnerabilty than
bypassing SCE.

Fixes angular#15144

Closes angular#15145
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants