mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-26 20:06:26 -08:00
add to sanitizer
This commit is contained in:
1 parent
2912b2c56c
commit
c9c3bf318c
1 file changed
+12
-2
@@ -1,5 +1,6 @@
|
||||
import DOMPurify from 'dompurify';
|
||||
import { isMatrixHexColor } from './matrixHtml';
|
||||
import { testMatrixUri } from '../plugins/matrix-uri';
|
||||
|
||||
const MAX_TAG_NESTING = 100;
|
||||
const INTERNAL_IMG_SRC_ATTR = 'data-sable-img-src';
|
||||
@@ -77,7 +78,7 @@ const forbiddenContentTags = ['mx-reply', 'script', 'style', 'textarea', 'option
|
||||
|
||||
const codeLanguageClassRegex = /^language-[A-Za-z0-9_-]+$/;
|
||||
const orderedListStartRegex = /^-?\d+$/;
|
||||
const allowedUriRegex = /^(?:https?|ftp|mailto|magnet|mxc):/i;
|
||||
const allowedUriRegex = /^(?:https?|ftp|mailto|magnet|mxc|matrix):/i;
|
||||
|
||||
export function sanitizeText(body: string): string {
|
||||
const tagsToReplace: Record<string, string> = {
|
||||
@@ -107,6 +108,10 @@ function isAllowedAbsoluteLink(value: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function isAllowedMatrixUri(value: string): boolean {
|
||||
return testMatrixUri(value);
|
||||
}
|
||||
|
||||
function isAllowedMxcUri(value: string): boolean {
|
||||
try {
|
||||
const parsed = new URL(value);
|
||||
@@ -152,7 +157,12 @@ function getValidatedAttributeValue(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (tagName === 'a' && attrName === 'href' && !isAllowedAbsoluteLink(attrValue)) {
|
||||
if (
|
||||
tagName === 'a' &&
|
||||
attrName === 'href' &&
|
||||
!isAllowedAbsoluteLink(attrValue) &&
|
||||
!isAllowedMatrixUri(attrValue)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user