security: fix complete multi-character sanitization for HTML comments in txt.ts (#3806)
* security: fix for code scanning alert no. 11: Incomplete multi-character sanitization Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix: use dotAll flag to match multi-line HTML comments Add the 's' flag to the comment-stripping regex so '.' matches newlines, ensuring comments spanning multiple lines are also removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: iterative dotAll sanitization in extractChaptersFromSegment Fixes code scanning alert #10 (incomplete multi-character sanitization). Apply the same fix as alert #11: replace one-shot comment stripping with an iterative loop using the 's' (dotAll) flag so nested and multi-line HTML comments are fully removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: iterative HTML tag sanitization in cleanDescription Fixes code scanning alert #9 (incomplete multi-character sanitization). Replace one-shot tag stripping with an iterative loop so crafted inputs like nested/overlapping tags cannot leave '<script' behind after a single replacement pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -208,9 +208,12 @@ export class GoogleBooksProvider extends BaseMetadataProvider {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return description
|
||||
.replace(/<[^>]*>/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
let sanitized = description;
|
||||
let previous: string;
|
||||
do {
|
||||
previous = sanitized;
|
||||
sanitized = sanitized.replace(/<[^>]*>/g, '');
|
||||
} while (sanitized !== previous);
|
||||
return sanitized.replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,7 +475,13 @@ export class TxtToEpubConverter {
|
||||
): Chapter[] {
|
||||
const { language } = metadata;
|
||||
const { fallbackParagraphsPerChapter } = option;
|
||||
const trimmedSegment = segment.replace(/<!--.*?-->/g, '').trim();
|
||||
let sanitizedSegment = segment;
|
||||
let previousSegment: string;
|
||||
do {
|
||||
previousSegment = sanitizedSegment;
|
||||
sanitizedSegment = sanitizedSegment.replace(/<!--.*?-->/gs, '');
|
||||
} while (sanitizedSegment !== previousSegment);
|
||||
const trimmedSegment = sanitizedSegment.trim();
|
||||
if (!trimmedSegment) return [];
|
||||
|
||||
const chapterRegexps = this.createChapterRegexps(language);
|
||||
|
||||
Reference in New Issue
Block a user