mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-30 16:47:13 +01:00
[MIRROR] HTML formatting on communication consoles, HTML sanitization (#1591)
* HTML formatting on communication consoles, HTML sanitization * 5 Co-authored-by: prodirus <44090982+prodirus@users.noreply.github.com> Co-authored-by: Gandalf <jzo123@hotmail.com>
This commit is contained in:
co-authored by
prodirus
Gandalf
parent
efedae3f66
commit
4e83fe51aa
@@ -3,6 +3,7 @@ import { capitalize } from "common/string";
|
||||
import { useBackend, useLocalState } from "../backend";
|
||||
import { Box, Button, Flex, Input, Modal, Section, Table, TextArea } from "../components";
|
||||
import { Window } from "../layouts";
|
||||
import { sanitizeText } from "../sanitize";
|
||||
|
||||
const STATE_BUYING_SHUTTLE = "buying_shuttle";
|
||||
const STATE_CHANGING_STATUS = "changing_status";
|
||||
@@ -609,6 +610,10 @@ const PageMessages = (props, context) => {
|
||||
);
|
||||
}
|
||||
|
||||
const textHtml = {
|
||||
__html: sanitizeText(message.content),
|
||||
};
|
||||
|
||||
messageElements.push((
|
||||
<Section
|
||||
title={message.title}
|
||||
@@ -623,7 +628,8 @@ const PageMessages = (props, context) => {
|
||||
})}
|
||||
/>
|
||||
)}>
|
||||
<Box>{message.content}</Box>
|
||||
<Box
|
||||
dangerouslySetInnerHTML={textHtml} />
|
||||
|
||||
{answers}
|
||||
</Section>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Uses DOMPurify to purify/sanitise HTML.
|
||||
*/
|
||||
|
||||
import DOMPurify from 'dompurify';
|
||||
|
||||
// Default values
|
||||
let defTag = [
|
||||
'br', 'code', 'li', 'p', 'pre',
|
||||
'span', 'table', 'td', 'tr', 'i',
|
||||
'th', 'ul', 'ol', 'menu', 'font', 'b',
|
||||
'center', 'table', 'tr', 'th', 'hr',
|
||||
];
|
||||
let defAttr = ['class', 'style'];
|
||||
|
||||
/**
|
||||
* Feed it a string and it should spit out a sanitized version.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {array} tags
|
||||
* @param {array} forbidAttr
|
||||
*/
|
||||
export const sanitizeText = (input, tags = defTag, forbidAttr = defAttr) => {
|
||||
// This is VERY important to think first if you NEED
|
||||
// the tag you put in here. We are pushing all this
|
||||
// though dangerouslySetInnerHTML and even though
|
||||
// the default DOMPurify kills javascript, it dosn't
|
||||
// kill href links or such
|
||||
return DOMPurify.sanitize(input, {
|
||||
ALLOWED_TAGS: tags,
|
||||
FORBID_ATTR: forbidAttr,
|
||||
});
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user