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

Commit 7618ca8

Browse files
committed
feat(security): do not bootstrap from unknown schemes with a different origin
1 parent d1e4f57 commit 7618ca8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Angular.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1485,12 +1485,14 @@ function allowAutoBootstrap(document) {
14851485
var src = document.currentScript.getAttribute('src');
14861486
var link = document.createElement('a');
14871487
link.href = src;
1488-
var scriptProtocol = link.protocol;
1489-
var docLoadProtocol = document.location.protocol;
1490-
if (docLoadProtocol === scriptProtocol) {
1488+
if (document.location.protocol === link.protocol && document.location.host === link.host) {
1489+
// Same-origin resources are always allowed, even for non-whitelisted schemes.
14911490
return true;
14921491
}
1493-
switch (scriptProtocol) {
1492+
// Disabled bootstrapping unless angular.js was loaded from a known scheme used on the web.
1493+
// This is to prevent angular.js bundled with browser extensions from being used to bypass the
1494+
// content security policy in web pages and other browser extensions.
1495+
switch (link.protocol) {
14941496
case 'http:':
14951497
case 'https:':
14961498
case 'ftp:':

test/AngularSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,20 @@ describe('angular', function() {
16831683
dealoc(appElement);
16841684
});
16851685

1686+
it('should bootstrap from an extension into an extension document for same-origin documents only', function() {
1687+
var src = 'resource://something';
1688+
// Fake a minimal document object (the actual document.currentScript is readonly).
1689+
var fakeDoc = {
1690+
currentScript: { getAttribute: function() { return src; } },
1691+
location: {protocol: 'resource:', origin: 'resource://something'},
1692+
createElement: document.createElement.bind(document)
1693+
};
1694+
expect(allowAutoBootstrap(fakeDoc)).toBe(true);
1695+
1696+
src = 'resource://something-else';
1697+
expect(allowAutoBootstrap(fakeDoc)).toBe(false);
1698+
});
1699+
16861700
it('should not bootstrap from an extension into a non-extension document', function() {
16871701
var src = 'resource://something';
16881702
// Fake a minimal document object (the actual document.currentScript is readonly).

0 commit comments

Comments
 (0)