Thanks to visit codestin.com
Credit goes to github.com

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

Commit f2fa1ed

Browse files
IgorMinargkalpak
authored andcommitted
fix($compile): properly sanitize xlink:href attribute interoplation
Closes #12524
1 parent f35f334 commit f2fa1ed

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/ng/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
768768
nodeName = nodeName_(this.$$element);
769769

770770
// sanitize a[href] and img[src] values
771-
if ((nodeName === 'A' && key === 'href') ||
771+
if ((nodeName === 'A' && (key === 'href' || key === 'xlinkHref')) ||
772772
(nodeName === 'IMG' && key === 'src')) {
773773
this[key] = value = $$sanitizeUri(value, key === 'src');
774774
}

test/ng/compileSpec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4787,6 +4787,37 @@ describe('$compile', function() {
47874787
});
47884788
});
47894789

4790+
it('should use $$sanitizeUri when declared via ng-href', function() {
4791+
var $$sanitizeUri = jasmine.createSpy('$$sanitizeUri');
4792+
module(function($provide) {
4793+
$provide.value('$$sanitizeUri', $$sanitizeUri);
4794+
});
4795+
inject(function($compile, $rootScope) {
4796+
element = $compile('<a ng-href="{{testUrl}}"></a>')($rootScope);
4797+
$rootScope.testUrl = "someUrl";
4798+
4799+
$$sanitizeUri.andReturn('someSanitizedUrl');
4800+
$rootScope.$apply();
4801+
expect(element.attr('href')).toBe('someSanitizedUrl');
4802+
expect($$sanitizeUri).toHaveBeenCalledWith($rootScope.testUrl, false);
4803+
});
4804+
});
4805+
4806+
it('should use $$sanitizeUri when working with svg and xlink:href', function() {
4807+
var $$sanitizeUri = jasmine.createSpy('$$sanitizeUri');
4808+
module(function($provide) {
4809+
$provide.value('$$sanitizeUri', $$sanitizeUri);
4810+
});
4811+
inject(function($compile, $rootScope) {
4812+
element = $compile('<svg><a xlink:href="" ng-href="{{ testUrl }}"></a></svg>')($rootScope);
4813+
$rootScope.testUrl = "evilUrl";
4814+
4815+
$$sanitizeUri.andReturn('someSanitizedUrl');
4816+
$rootScope.$apply();
4817+
expect(element.find('a').prop('href').baseVal).toBe('someSanitizedUrl');
4818+
expect($$sanitizeUri).toHaveBeenCalledWith($rootScope.testUrl, false);
4819+
});
4820+
});
47904821
});
47914822

47924823
describe('interpolation on HTML DOM event handler attributes onclick, onXYZ, formaction', function() {

0 commit comments

Comments
 (0)