html-tagged-template.js: Authorize more protocols

https://github.com/straker/html-tagged-template/issues/26 discusses
authorizing the data:// protocol. The gist of it is that it's dangerous
because data:text/html can be used for XSS attacks. We circumvent this
problem by only explicitly allowing a few image formats formatted as
base64.
This commit is contained in:
glacambre 2019-01-18 19:20:21 +01:00
parent d1ce62ec6d
commit 3ddf350dc0
No known key found for this signature in database
GPG key ID: B9625DB1767553AC

View file

@ -457,14 +457,24 @@
substitutionValue.indexOf(":") !==
-1
) {
let protocol = substitutionValue.substring(
0,
5,
)
const authorized_protocols = [
"http://",
"https://",
"moz-extension://",
"about://",
"data:image/png;base64",
"data:image/gif;base64",
"data:image/jpg;base64",
"data:image/jpeg;base64",
"data:image/x-icon;base64",
]
// If substitutionValue doesn't start with any of the authorized protocols
if (
protocol.indexOf("http") ===
-1 &&
protocol.indexOf("moz-") == -1
!authorized_protocols.find(p =>
substitutionValue.startsWith(
p,
),
)
) {
isRejected = true
}