Skip to content

Commit 5116fde

Browse files
committed
fix(util): Use safevalues to sanitize HTML strings
1 parent 1933324 commit 5116fde

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
@@ -144,6 +144,7 @@
144144
"prettier": "2.8.8",
145145
"protractor": "5.4.2",
146146
"request": "2.88.2",
147+
"safevalues": "1.2.0",
147148
"semver": "7.7.1",
148149
"simple-git": "3.27.0",
149150
"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
@@ -14436,6 +14436,11 @@ safe-stable-stringify@^2.3.1:
1443614436
resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
1443714437
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
1443814438

14439+
14440+
version "1.2.0"
14441+
resolved "https://registry.npmjs.org/safevalues/-/safevalues-1.2.0.tgz#f9e646d6ebf31788004ef192d2a7d646c9896bb2"
14442+
integrity sha512-zIsuhjYvJCjfsfjoim2ab6gLKFYAnTiDSJGh0cC3T44L/4kNLL90hBG2BzrXPrHA3f8Ms8FSJ1mljKH5dVR1cw==
14443+
1443914444
sauce-connect-launcher@^1.2.7:
1444014445
version "1.3.2"
1444114446
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:
1534515350
resolved "https://registry.npmjs.org/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6"
1534615351
integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==
1534715352

15348-
"string-width-cjs@npm:string-width@^4.2.0":
15353+
"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:
1534915354
version "4.2.3"
1535015355
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1535115356
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -15363,15 +15368,6 @@ string-width@^1.0.1, string-width@^1.0.2:
1536315368
is-fullwidth-code-point "^1.0.0"
1536415369
strip-ansi "^3.0.0"
1536515370

15366-
"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:
15367-
version "4.2.3"
15368-
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
15369-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
15370-
dependencies:
15371-
emoji-regex "^8.0.0"
15372-
is-fullwidth-code-point "^3.0.0"
15373-
strip-ansi "^6.0.1"
15374-
1537515371
string-width@^2.1.1:
1537615372
version "2.1.1"
1537715373
resolved "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
@@ -15435,7 +15431,7 @@ string_decoder@~1.1.1:
1543515431
dependencies:
1543615432
safe-buffer "~5.1.0"
1543715433

15438-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
15434+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1543915435
version "6.0.1"
1544015436
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1544115437
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -15456,13 +15452,6 @@ strip-ansi@^4.0.0:
1545615452
dependencies:
1545715453
ansi-regex "^3.0.0"
1545815454

15459-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
15460-
version "6.0.1"
15461-
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
15462-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
15463-
dependencies:
15464-
ansi-regex "^5.0.1"
15465-
1546615455
strip-ansi@^7.0.1:
1546715456
version "7.1.0"
1546815457
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -17145,7 +17134,7 @@ [email protected]:
1714517134
resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.2.0.tgz#827d93c9ba23ee2019c3ffaff5c27fccea289e8b"
1714617135
integrity sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A==
1714717136

17148-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
17137+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1714917138
version "7.0.0"
1715017139
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1715117140
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -17179,15 +17168,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
1717917168
string-width "^4.1.0"
1718017169
strip-ansi "^6.0.0"
1718117170

17182-
wrap-ansi@^7.0.0:
17183-
version "7.0.0"
17184-
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
17185-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
17186-
dependencies:
17187-
ansi-styles "^4.0.0"
17188-
string-width "^4.1.0"
17189-
strip-ansi "^6.0.0"
17190-
1719117171
wrap-ansi@^8.1.0:
1719217172
version "8.1.0"
1719317173
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)