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

fix($compile) empty href should pass sanitation check #2593

Closed
wants to merge 1 commit into from
Closed

fix($compile) empty href should pass sanitation check #2593

wants to merge 1 commit into from

Conversation

andershessellund
Copy link
Contributor

The htmlAnchorDirective sets an empty href attribute on tags.
This should pass sanitation check in $compile.

Closes #2219

@petebacondarwin
Copy link
Member

Can you provide a unit test for this?

@andershessellund
Copy link
Contributor Author

I have attempted to create a unit test for this problem. Unfortunately it is very difficult to reproduce.

The problem is in the following code from $compile:

        // sanitize a[href] values
        if (nodeName_(this.$$element[0]) === 'A' && key === 'href') {
          urlSanitizationNode.setAttribute('href', value);

          // href property always returns normalized absolute url, so we can match against that
          normalizedVal = urlSanitizationNode.href;
          if (!normalizedVal.match(urlSanitizationWhitelist)) {
            this[key] = value = 'unsafe:' + normalizedVal;
          }
        }

Under NORMAL circumstances, the urlSanitizationNode.href returns a normalized absolute URL - including the problematic case, where the href is set to the empty string. However, under certain circumstances, which i don't fully understand, IE7 and IE8 returns an empty String. I cannot seem to reproduce this in a simple test case, and in my application the error is also not 100% reproducible - somtimes, it happens, sometimes it does not.

The htmlAnchorDirective sets an empty href attribute on <a> tags.
This should pass sanitation check in $compile.

Closes #2219
@pstoica
Copy link

pstoica commented Jun 12, 2013

Any updates to this? I'm still receiving "unsafe:" links on IE7 using ng-href.

@andershessellund
Copy link
Contributor Author

No updates that I know of, I do not think the angular devs will accept a bugfix without a test to reproduce the bug - which unfortunately is very difficult in this case.

Have you been able to reproduce the bug in a small example?

@pstoica
Copy link

pstoica commented Jun 16, 2013

http://run.plnkr.co/BEpuj4YKdnSjbroM/ Try this out. It's been occurring precisely for me using routeProvider.

@andershessellund
Copy link
Contributor Author

I get a 404 when loading the plunk for some reason. I am sure it was available yesterday. Could you please upload it again?

@pstoica
Copy link

pstoica commented Jun 17, 2013

Sorry about that. Try this: http://run.plnkr.co/plunks/ImUdcyAWAHr63oWVbgxt/

And if not that, here's the plunkr directly: http://plnkr.co/ImUdcyAWAHr63oWVbgxt
Just hit "Launch Fullscreen".

@deanapeterson
Copy link
Contributor

To get around this. You can add a non empty name attribute.

<a href="" name="ie7Sucks" ng-click="[exp]">Click</a>

petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Jul 3, 2013
Sometimes IE returns an empty string for its normalized href on a tags.
This should pass the sanitation check in $compile.

Closes angular#2219, angular#2593
petebacondarwin pushed a commit that referenced this pull request Jul 3, 2013
Sometimes IE returns an empty string for its normalized href on a tags.
This should pass the sanitation check in $compile.

Closes #2219, #2593
@petebacondarwin
Copy link
Member

You are right that this is incredibly hard to unit test without exposing internals of $compile.
Merging as-is since it is an almost trivial change and doesn't break any of the other tests.
Landed as fc8c9ba and 3b2c6f0

ctrahey pushed a commit to ctrahey/angular.js that referenced this pull request Jul 22, 2013
Sometimes IE returns an empty string for its normalized href on a tags.
This should pass the sanitation check in $compile.

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

Successfully merging this pull request may close these issues.

anchor tag <a> doesn't work without href because of unsafe: link (IE 8 and below)
4 participants