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

Commit 7f1b8bd

Browse files
authored
feat(security): explicitly whitelist URL schemes for bootstrap. (#15427)
Many browsers have some extension URL scheme. It is unclear how many of those have the security issue of allowing parser-inserted loads of extension URLs. To be conservative, this code whitelists the URL schemes that are known to be subject to CSP, i.e. the ones that are expected and safe.
1 parent cc92da0 commit 7f1b8bd

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Angular.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -1455,12 +1455,20 @@ function allowAutoBootstrap(document) {
14551455
link.href = src;
14561456
var scriptProtocol = link.protocol;
14571457
var docLoadProtocol = document.location.protocol;
1458-
if ((scriptProtocol === 'resource:' ||
1459-
scriptProtocol === 'chrome-extension:') &&
1460-
docLoadProtocol !== scriptProtocol) {
1461-
return false;
1458+
if (docLoadProtocol === scriptProtocol) {
1459+
return true;
1460+
}
1461+
switch(scriptProtocol) {
1462+
case 'http:':
1463+
case 'https:':
1464+
case 'ftp:':
1465+
case 'blob:':
1466+
case 'file:':
1467+
case 'data:':
1468+
return true;
1469+
default:
1470+
return false;
14621471
}
1463-
return true;
14641472
}
14651473

14661474
// Cached as it has to run during loading so that document.currentScript is available.

0 commit comments

Comments
 (0)