Skip to content

Commit b1c60ca

Browse files
committed
fix(util): Use safevalues to sanitize HTML strings
1 parent 5e80c6a commit b1c60ca

File tree

5 files changed

+22
-33
lines changed

5 files changed

+22
-33
lines changed

.changeset/honest-parents-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/util': patch
3+
---
4+
5+
Use `safevalues` to sanitize HTML strings that are attached to the DOM

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"protractor": "5.4.2",
146146
"protobufjs-cli": "^1.1.3",
147147
"request": "2.88.2",
148+
"safevalues": "1.2.0",
148149
"semver": "7.7.1",
149150
"simple-git": "3.27.0",
150151
"sinon": "9.2.4",

packages/util/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"license": "Apache-2.0",
4646
"dependencies": {
47+
"safevalues": "1.2.0",
4748
"tslib": "^2.1.0"
4849
},
4950
"devDependencies": {

packages/util/src/emulator.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import { base64urlEncodeWithoutPadding } from './crypt';
1919
import { isCloudWorkstation } from './url';
20+
import { sanitizeHtml } from 'safevalues';
21+
import { setElementInnerHtml } from 'safevalues/dom';
2022

2123
// Firebase Auth tokens contain snake_case claims following the JWT standard / convention.
2224
/* eslint-disable camelcase */
@@ -242,7 +244,7 @@ export function updateEmulatorBanner(
242244
closeBtn.style.cursor = 'pointer';
243245
closeBtn.style.marginLeft = '16px';
244246
closeBtn.style.fontSize = '24px';
245-
closeBtn.innerHTML = ' ×';
247+
setElementInnerHtml(closeBtn, sanitizeHtml(' ×'));
246248
closeBtn.onclick = () => {
247249
previouslyDismissed = true;
248250
tearDown();
@@ -291,23 +293,23 @@ export function updateEmulatorBanner(
291293

292294
if (showError) {
293295
firebaseText.innerText = `Preview backend disconnected.`;
294-
prependIcon.innerHTML = `<g clip-path="url(#clip0_6013_33858)">
296+
setElementInnerHtml(prependIcon, sanitizeHtml(`<g clip-path="url(#clip0_6013_33858)">
295297
<path d="M4.8 17.6L12 5.6L19.2 17.6H4.8ZM6.91667 16.4H17.0833L12 7.93333L6.91667 16.4ZM12 15.6C12.1667 15.6 12.3056 15.5444 12.4167 15.4333C12.5389 15.3111 12.6 15.1667 12.6 15C12.6 14.8333 12.5389 14.6944 12.4167 14.5833C12.3056 14.4611 12.1667 14.4 12 14.4C11.8333 14.4 11.6889 14.4611 11.5667 14.5833C11.4556 14.6944 11.4 14.8333 11.4 15C11.4 15.1667 11.4556 15.3111 11.5667 15.4333C11.6889 15.5444 11.8333 15.6 12 15.6ZM11.4 13.6H12.6V10.4H11.4V13.6Z" fill="#212121"/>
296298
</g>
297299
<defs>
298300
<clipPath id="clip0_6013_33858">
299301
<rect width="24" height="24" fill="white"/>
300302
</clipPath>
301-
</defs>`;
303+
</defs>`));
302304
} else {
303-
prependIcon.innerHTML = `<g clip-path="url(#clip0_6083_34804)">
305+
setElementInnerHtml(prependIcon, sanitizeHtml(`<g clip-path="url(#clip0_6083_34804)">
304306
<path d="M11.4 15.2H12.6V11.2H11.4V15.2ZM12 10C12.1667 10 12.3056 9.94444 12.4167 9.83333C12.5389 9.71111 12.6 9.56667 12.6 9.4C12.6 9.23333 12.5389 9.09444 12.4167 8.98333C12.3056 8.86111 12.1667 8.8 12 8.8C11.8333 8.8 11.6889 8.86111 11.5667 8.98333C11.4556 9.09444 11.4 9.23333 11.4 9.4C11.4 9.56667 11.4556 9.71111 11.5667 9.83333C11.6889 9.94444 11.8333 10 12 10ZM12 18.4C11.1222 18.4 10.2944 18.2333 9.51667 17.9C8.73889 17.5667 8.05556 17.1111 7.46667 16.5333C6.88889 15.9444 6.43333 15.2611 6.1 14.4833C5.76667 13.7056 5.6 12.8778 5.6 12C5.6 11.1111 5.76667 10.2833 6.1 9.51667C6.43333 8.73889 6.88889 8.06111 7.46667 7.48333C8.05556 6.89444 8.73889 6.43333 9.51667 6.1C10.2944 5.76667 11.1222 5.6 12 5.6C12.8889 5.6 13.7167 5.76667 14.4833 6.1C15.2611 6.43333 15.9389 6.89444 16.5167 7.48333C17.1056 8.06111 17.5667 8.73889 17.9 9.51667C18.2333 10.2833 18.4 11.1111 18.4 12C18.4 12.8778 18.2333 13.7056 17.9 14.4833C17.5667 15.2611 17.1056 15.9444 16.5167 16.5333C15.9389 17.1111 15.2611 17.5667 14.4833 17.9C13.7167 18.2333 12.8889 18.4 12 18.4ZM12 17.2C13.4444 17.2 14.6722 16.6944 15.6833 15.6833C16.6944 14.6722 17.2 13.4444 17.2 12C17.2 10.5556 16.6944 9.32778 15.6833 8.31667C14.6722 7.30555 13.4444 6.8 12 6.8C10.5556 6.8 9.32778 7.30555 8.31667 8.31667C7.30556 9.32778 6.8 10.5556 6.8 12C6.8 13.4444 7.30556 14.6722 8.31667 15.6833C9.32778 16.6944 10.5556 17.2 12 17.2Z" fill="#212121"/>
305307
</g>
306308
<defs>
307309
<clipPath id="clip0_6083_34804">
308310
<rect width="24" height="24" fill="white"/>
309311
</clipPath>
310-
</defs>`;
312+
</defs>`));
311313
firebaseText.innerText = 'Preview backend running in this workspace.';
312314
}
313315
firebaseText.setAttribute('id', firebaseTextId);

yarn.lock

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14643,6 +14643,11 @@ safe-stable-stringify@^2.3.1:
1464314643
resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
1464414644
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
1464514645

14646+
14647+
version "1.2.0"
14648+
resolved "https://registry.npmjs.org/safevalues/-/safevalues-1.2.0.tgz#f9e646d6ebf31788004ef192d2a7d646c9896bb2"
14649+
integrity sha512-zIsuhjYvJCjfsfjoim2ab6gLKFYAnTiDSJGh0cC3T44L/4kNLL90hBG2BzrXPrHA3f8Ms8FSJ1mljKH5dVR1cw==
14650+
1464614651
sauce-connect-launcher@^1.2.7:
1464714652
version "1.3.2"
1464814653
resolved "https://registry.npmjs.org/sauce-connect-launcher/-/sauce-connect-launcher-1.3.2.tgz#dfc675a258550809a8eaf457eb9162b943ddbaf0"
@@ -15557,7 +15562,7 @@ string-argv@~0.3.1:
1555715562
resolved "https://registry.npmjs.org/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6"
1555815563
integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==
1555915564

15560-
"string-width-cjs@npm:string-width@^4.2.0":
15565+
"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:
1556115566
version "4.2.3"
1556215567
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1556315568
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -15575,15 +15580,6 @@ string-width@^1.0.1, string-width@^1.0.2:
1557515580
is-fullwidth-code-point "^1.0.0"
1557615581
strip-ansi "^3.0.0"
1557715582

15578-
"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:
15579-
version "4.2.3"
15580-
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
15581-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
15582-
dependencies:
15583-
emoji-regex "^8.0.0"
15584-
is-fullwidth-code-point "^3.0.0"
15585-
strip-ansi "^6.0.1"
15586-
1558715583
string-width@^2.1.1:
1558815584
version "2.1.1"
1558915585
resolved "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
@@ -15647,7 +15643,7 @@ string_decoder@~1.1.1:
1564715643
dependencies:
1564815644
safe-buffer "~5.1.0"
1564915645

15650-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
15646+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1565115647
version "6.0.1"
1565215648
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1565315649
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -15668,13 +15664,6 @@ strip-ansi@^4.0.0:
1566815664
dependencies:
1566915665
ansi-regex "^3.0.0"
1567015666

15671-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
15672-
version "6.0.1"
15673-
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
15674-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
15675-
dependencies:
15676-
ansi-regex "^5.0.1"
15677-
1567815667
strip-ansi@^7.0.1:
1567915668
version "7.1.0"
1568015669
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -17369,7 +17358,7 @@ [email protected]:
1736917358
resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.2.0.tgz#827d93c9ba23ee2019c3ffaff5c27fccea289e8b"
1737017359
integrity sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A==
1737117360

17372-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
17361+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1737317362
version "7.0.0"
1737417363
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1737517364
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -17403,15 +17392,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
1740317392
string-width "^4.1.0"
1740417393
strip-ansi "^6.0.0"
1740517394

17406-
wrap-ansi@^7.0.0:
17407-
version "7.0.0"
17408-
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
17409-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
17410-
dependencies:
17411-
ansi-styles "^4.0.0"
17412-
string-width "^4.1.0"
17413-
strip-ansi "^6.0.0"
17414-
1741517395
wrap-ansi@^8.1.0:
1741617396
version "8.1.0"
1741717397
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)