Skip to content

Commit

Permalink
fix URL contextual auto-escapping preventing good URL protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Feb 3, 2017
1 parent ffd826f commit 872c5d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ if (typeof window.html === 'undefined') {
// the entire url (will not allow any 'javascript:' or filter
// evasion techniques)
if (offset === 0 && substitutionValue.indexOf(':') !== -1) {
let protocol = substitutionValue.substring(index-5, index);
let protocol = substitutionValue.substring(0, 5);
if (protocol.indexOf('http') === -1) {
isRejected = true;
}
Expand Down
13 changes: 13 additions & 0 deletions test/xss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,17 @@ describe('XSS Attack Vectors', function() {
expect(el.getAttribute('href').indexOf('/bar')).to.equal(-1);
});

it('should allow a URL if it has a safe protocol', function() {
var protocol = 'http://localhost:500';
var value = '/foo?id=true';
var el = html`<a href="${protocol}/bar${value}">`;

expect(el.getAttribute('href')).to.equal('http://localhost:500/bar/foo?id=true');

var protocol = 'https://localhost:500';
var el = html`<a href="${protocol}/bar${value}">`;

expect(el.getAttribute('href')).to.equal('https://localhost:500/bar/foo?id=true');
});

});

0 comments on commit 872c5d0

Please sign in to comment.