fixup! TF-4224 Reduce ReDoS vulnerability

This commit is contained in:
Dang Dat
2025-12-24 15:05:45 +07:00
committed by Dat H. Pham
parent 86dec27d67
commit a8f90ec700
3 changed files with 39 additions and 12 deletions
+5 -6
View File
@@ -34,6 +34,10 @@ class HtmlUtils {
multiLine: true,
);
static final _protocolRegex = RegExp(r'^(?:https?|ftp|mailto|file)');
static final _tagRemovalRegex = RegExp(
'</?(?:${validTags.map(RegExp.escape).join('|')})(?:\\s+[^>]*)?>',
caseSensitive: false,
);
static const removeLineHeight1px = (
script: '''
@@ -861,12 +865,7 @@ class HtmlUtils {
} while (decoded != cleaned && iterations < maxIterations);
// Delete all remaining HTML tags → replace tag with space to avoid text sticking
final String tagsPipe = validTags.map(RegExp.escape).join('|');
final tagRegex = RegExp(
'</?(?:$tagsPipe)(?:\\s+[^>]*)?>',
caseSensitive: false,
);
cleaned = cleaned.replaceAll(tagRegex, ' ');
cleaned = cleaned.replaceAll(_tagRemovalRegex, ' ');
// Normalize whitespace
cleaned = cleaned.replaceAll(_whitespaceNormalizationRegex, ' ').trim();