This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +20
-4
lines changed
2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -1485,12 +1485,14 @@ function allowAutoBootstrap(document) {
1485
1485
var src = document . currentScript . getAttribute ( 'src' ) ;
1486
1486
var link = document . createElement ( 'a' ) ;
1487
1487
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.
1491
1490
return true ;
1492
1491
}
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 ) {
1494
1496
case 'http:' :
1495
1497
case 'https:' :
1496
1498
case 'ftp:' :
Original file line number Diff line number Diff line change @@ -1683,6 +1683,20 @@ describe('angular', function() {
1683
1683
dealoc ( appElement ) ;
1684
1684
} ) ;
1685
1685
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
+
1686
1700
it ( 'should not bootstrap from an extension into a non-extension document' , function ( ) {
1687
1701
var src = 'resource://something' ;
1688
1702
// Fake a minimal document object (the actual document.currentScript is readonly).
You can’t perform that action at this time.
0 commit comments