Skip to content

Commit

Permalink
Dont falsely report protocol relative href urls as violating the mixe…
Browse files Browse the repository at this point in the history
…d-content rule
  • Loading branch information
Munter committed Feb 8, 2017
1 parent 998b075 commit 6b8c82e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ module.exports = function (options) {
});

if (secureSourceRelations.length > 0) {
var hasInsecureTarget = url.indexOf('https:') !== 0 || redirects.some(function (redirect) {
return redirect.redirectUri.indexOf('https:') !== 0;
var hasSecureTarget = /^(?:https:)?\/\//.test(url) && redirects.every(function (redirect) {
return /^(?:https:)?\/\//.test(redirect.redirectUri);
});

if (hasInsecureTarget) {
if (!hasSecureTarget) {
var insecureLog = [].concat({ redirectUri: url }, redirects).map(function (item, idx, arr) {
if (arr[idx + 1]) {
item.statusCode = arr[idx + 1].statusCode;
Expand Down Expand Up @@ -250,11 +250,7 @@ module.exports = function (options) {
crossorigin: true,
href: /^(?:https?:)?\/\//
}, true), function (relation) {
var url = relation.href.replace(/#.*$/, '');

if (relation.hrefType === 'protocolRelative') {
url = 'http:' + url;
}
var url = relation.to.url.replace(/#.*$/, '');

return url;
});
Expand Down

0 comments on commit 6b8c82e

Please sign in to comment.