diff options
| author | Osmium Sorcerer <os@sof.beauty> | 2026-06-03 11:23:33 +0000 |
|---|---|---|
| committer | Osmium Sorcerer <os@sof.beauty> | 2026-06-06 03:09:27 +0000 |
| commit | fd75f3116aa30eb4958cc747f944f202ec69a484 (patch) | |
| tree | 2afb99a17a2fe3c832c8eae0f0e7594ea806b7e9 /webAO/encoding.ts | |
| parent | bd8b53cd6046cef9802d593d8257392d81afb5ce (diff) | |
Remove safeTags, decodeChat, and prepChat
Following the removal of innerHTML manipulation, we no longer need these
sanitization functions.
I've reviewed every safeTags call site to make sure the outputs don't
end up anywhere unsafe, and malicious input can't malipulate DOM or
execute code. These values either end up either as plain text
(textContent, innerText, createTextNode, title, option) or as a URL
path to request assets to the server (encoded using encodeURI).
That is, if safeTags was even effective, considering all that function
did was replace '<' and '>' symbols with Unicode lookalikes. Even the
comment was suggesting the use of fundamentally safer functions instead
of these hacks.
Replace remaining uses of prepChat with unescapeChat as we still need
to do the token substitution (like "<and>" to "&"). decodeChat was
escaping Unicode sequences like \uXXXX, but I don't see the reason for
this, AO2 Client doesn't have this feature, and considering WebSocket
text frames are strictly UTF-8, we don't need these encodings.
Diffstat (limited to 'webAO/encoding.ts')
| -rw-r--r-- | webAO/encoding.ts | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/webAO/encoding.ts b/webAO/encoding.ts index 37f064a9..1c380f7d 100644 --- a/webAO/encoding.ts +++ b/webAO/encoding.ts @@ -21,36 +21,3 @@ export function unescapeChat(estring: string): string { .replaceAll("<percent>", "%") .replaceAll("<dollar>", "$"); } - -/** - * Escapes a string to be HTML-safe. - * - * XXX: This is unnecessary if we use `createTextNode` instead! - * @param {string} unsafe an unsanitized string - */ -export function safeTags(unsafe: string): string { - if (unsafe) { - return unsafe.replaceAll(">", ">").replaceAll("<", "<"); - } - return ""; -} - -/** - * Decodes text on client side. - * @param {string} estring the string to be decoded - */ -export function decodeChat(estring: string): string { - // Source: https://stackoverflow.com/questions/7885096/how-do-i-decode-a-string-with-escaped-unicode - return estring.replace(/\\u([\d\w]{1,})/gi, (match, group) => - String.fromCharCode(parseInt(group, 16)), - ); -} - -/** - * XXX: a nasty hack made by gameboyprinter. - * @param {string} msg chat message to prepare for display - */ -export function prepChat(msg: string): string { - // TODO: make this less awful - return safeTags(unescapeChat(decodeChat(msg))); -} |
