Skip to content

Commit

Permalink
Added SSL mixed content detection for external content
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed Jul 23, 2015
1 parent 22bce25 commit 6d57ec7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,46 @@ module.exports = function (options) {
}

t.push(null, report);

// Check for mixed-content warnings
var secureSourceRelations = relations.filter(function (relation) {
return relation.type !== 'HtmlAnchor' && relation.from.nonInlineAncestor.url.indexOf('https:') === 0;
});

if (secureSourceRelations.length > 0) {
var hasInsecureTarget = url.indexOf('htps:') !== 0 || redirects.some(function (redirect) {
return redirect.redirectUri.indexOf('https:') !== 0;
});

if (hasInsecureTarget) {
var insecureLog = [].concat({ redirectUri: url }, redirects).map(function (item, idx, arr) {
if (arr[idx + 1]) {
item.statusCode = arr[idx + 1].statusCode;
} else {
item.statusCode = 200;
}

return item;
});

var insecureLogLine = insecureLog.map(function (redirect) {
return redirect.redirectUri;
}).join(' --> ');

var insecureReport = {
ok: false,
name: 'URI should be secure - ' + url,
operator: 'mixed-content',
expected: insecureLogLine.replace(/\bhttps?:/g, 'https:'),
actual: insecureLogLine,
at: _.uniq(relations.map(function (relation) {
return relation.from.urlOrDescription.replace(/#.*$/, '');
})).join('\n ')
};

t.push(null, insecureReport);
}
}
}

function httpStatus(url, relations) {
Expand Down

2 comments on commit 6d57ec7

@papandreou
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 This is pretty clever!

@Munter
Copy link
Owner Author

@Munter Munter commented on 6d57ec7 Aug 5, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing the same check for internal links though

Please sign in to comment.