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

fix: bootstrap check with alternate anchor properties #16031

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,8 @@ function allowAutoBootstrap(document) {
var link = document.createElement('a');
link.href = src.value;

if (document.location.origin === link.origin) {
if (document.location.protocol === link.protocol && document.location.hostname === link.hostname &&
document.location.port === link.port) {
// Same-origin resources are always allowed, even for non-whitelisted schemes.
return true;
}
Expand Down
22 changes: 6 additions & 16 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,8 @@ describe('angular', function() {
function createFakeDoc(attrs, protocol, currentScript) {

protocol = protocol || 'http:';
var origin = protocol + '//something';
var hostname = 'something';
var origin = protocol + '//' + hostname;

if (currentScript === undefined) {
currentScript = document.createElement('script');
Expand All @@ -1726,7 +1727,7 @@ describe('angular', function() {
// Fake a minimal document object (the actual document.currentScript is readonly).
return {
currentScript: currentScript,
location: {protocol: protocol, origin: origin},
location: {protocol: protocol, origin: origin, hostname: hostname, host: hostname, port: ''},
createElement: document.createElement.bind(document)
};
}
Expand All @@ -1749,20 +1750,9 @@ describe('angular', function() {
}


if (protocol === 'ms-browser-extension:') {
// Support: Edge 13-15
// In Edge, URLs with protocol 'ms-browser-extension:' return "null" for the origin,
// therefore it's impossible to know if a script is same-origin.
it('should not bootstrap for same-origin documents', function() {
expect(allowAutoBootstrap(createFakeDoc({src: protocol + '//something'}, protocol))).toBe(false);
});

} else {
it('should bootstrap for same-origin documents', function() {

expect(allowAutoBootstrap(createFakeDoc({src: protocol + '//something'}, protocol))).toBe(true);
});
}
it('should bootstrap for same-origin documents', function() {
expect(allowAutoBootstrap(createFakeDoc({src: protocol + '//something'}, protocol))).toBe(true);
});

it('should not bootstrap for cross-origin documents', function() {
expect(allowAutoBootstrap(createFakeDoc({src: protocol + '//something-else'}, protocol))).toBe(false);
Expand Down