diff --git a/.changeset/honest-parents-drive.md b/.changeset/honest-parents-drive.md new file mode 100644 index 00000000000..98fcbbe313c --- /dev/null +++ b/.changeset/honest-parents-drive.md @@ -0,0 +1,5 @@ +--- +'@firebase/util': patch +--- + +Use `safevalues` to sanitize HTML strings that are attached to the DOM diff --git a/.changeset/metal-adults-eat.md b/.changeset/metal-adults-eat.md new file mode 100644 index 00000000000..db98c98108a --- /dev/null +++ b/.changeset/metal-adults-eat.md @@ -0,0 +1,5 @@ +--- +'@firebase/util': patch +--- + +Use `safevalues` to sanitize HTML that is attached to the DOM diff --git a/package.json b/package.json index 30b6b09a003..14d044cb960 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,7 @@ "prettier": "2.8.8", "protractor": "5.4.2", "request": "2.88.2", + "safevalues": "1.2.0", "semver": "7.7.1", "simple-git": "3.27.0", "sinon": "9.2.4", diff --git a/packages/util/package.json b/packages/util/package.json index 8a1ebb49dd5..b737cd6369f 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -44,6 +44,7 @@ }, "license": "Apache-2.0", "dependencies": { + "safevalues": "1.2.0", "tslib": "^2.1.0" }, "devDependencies": { diff --git a/packages/util/src/emulator.ts b/packages/util/src/emulator.ts index 1c4d4ae7a7d..98685d85820 100644 --- a/packages/util/src/emulator.ts +++ b/packages/util/src/emulator.ts @@ -17,6 +17,8 @@ import { base64urlEncodeWithoutPadding } from './crypt'; import { isCloudWorkstation } from './url'; +import { sanitizeHtml } from 'safevalues'; +import { setElementInnerHtml } from 'safevalues/dom'; // Firebase Auth tokens contain snake_case claims following the JWT standard / convention. /* eslint-disable camelcase */ @@ -242,7 +244,7 @@ export function updateEmulatorBanner( closeBtn.style.cursor = 'pointer'; closeBtn.style.marginLeft = '16px'; closeBtn.style.fontSize = '24px'; - closeBtn.innerHTML = ' ×'; + setElementInnerHtml(closeBtn, sanitizeHtml(' ×')); closeBtn.onclick = () => { previouslyDismissed = true; tearDown(); @@ -291,23 +293,23 @@ export function updateEmulatorBanner( if (showError) { firebaseText.innerText = `Preview backend disconnected.`; - prependIcon.innerHTML = ` + setElementInnerHtml(prependIcon, sanitizeHtml(` -`; +`)); } else { - prependIcon.innerHTML = ` + setElementInnerHtml(prependIcon, sanitizeHtml(` -`; +`)); firebaseText.innerText = 'Preview backend running in this workspace.'; } firebaseText.setAttribute('id', firebaseTextId); diff --git a/yarn.lock b/yarn.lock index 51ede769d03..771ead94a72 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14436,6 +14436,11 @@ safe-stable-stringify@^2.3.1: resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== +safevalues@1.2.0: + version "1.2.0" + resolved "https://registry.npmjs.org/safevalues/-/safevalues-1.2.0.tgz#f9e646d6ebf31788004ef192d2a7d646c9896bb2" + integrity sha512-zIsuhjYvJCjfsfjoim2ab6gLKFYAnTiDSJGh0cC3T44L/4kNLL90hBG2BzrXPrHA3f8Ms8FSJ1mljKH5dVR1cw== + sauce-connect-launcher@^1.2.7: version "1.3.2" resolved "https://registry.npmjs.org/sauce-connect-launcher/-/sauce-connect-launcher-1.3.2.tgz#dfc675a258550809a8eaf457eb9162b943ddbaf0" @@ -15345,7 +15350,7 @@ string-argv@~0.3.1: resolved "https://registry.npmjs.org/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6" integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q== -"string-width-cjs@npm:string-width@^4.2.0": +"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -15363,15 +15368,6 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^1.0.0" strip-ansi "^3.0.0" -"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: - version "4.2.3" - resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - string-width@^2.1.1: version "2.1.1" resolved "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" @@ -15435,7 +15431,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -15456,13 +15452,6 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -17145,7 +17134,7 @@ workerpool@6.2.0: resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.2.0.tgz#827d93c9ba23ee2019c3ffaff5c27fccea289e8b" integrity sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -17179,15 +17168,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"