-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(html-sanitizer): only warn if sanitization is attempted
- Loading branch information
1 parent
ef1d9e1
commit 82beb9b
Showing
1 changed file
with
10 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
import { getLogger } from 'aurelia-logging'; | ||
|
||
const SCRIPT_REGEX = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi; | ||
let needsToWarn = true; | ||
|
||
/** | ||
* Default Html Sanitizer to prevent script injection. | ||
*/ | ||
export class HTMLSanitizer { | ||
constructor() { | ||
getLogger('html-sanitizer') | ||
.warn(`CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks, | ||
and should not be relied on for sanitizing input from unknown sources. | ||
Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.`); | ||
} | ||
|
||
/** | ||
* Sanitizes the provided input. | ||
* @param input The input to be sanitized. | ||
*/ | ||
sanitize(input) { | ||
if (needsToWarn) { | ||
needsToWarn = false; | ||
|
||
getLogger('html-sanitizer') | ||
.warn(`CAUTION: The default HTMLSanitizer does NOT provide security against a wide variety of sophisticated XSS attacks, | ||
and should not be relied on for sanitizing input from unknown sources. | ||
Please see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.`); | ||
} | ||
|
||
return input.replace(SCRIPT_REGEX, ''); | ||
} | ||
} |