-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into fix/parsing-envs
- Loading branch information
Showing
5 changed files
with
399 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
Highcharts Export Server | ||
Copyright (c) 2016-2024, Highsoft | ||
Licenced under the MIT licence. | ||
Additionally a valid Highcharts license is required for use. | ||
See LICENSE file in root for details. | ||
*******************************************************************************/ | ||
|
||
/** | ||
* @overview Used to sanitize the strings coming from the exporting module | ||
* to prevent XSS attacks (with the DOMPurify library). | ||
**/ | ||
|
||
import { JSDOM } from 'jsdom'; | ||
import DOMPurify from 'dompurify'; | ||
|
||
/** | ||
* Sanitizes a given HTML string by removing <script> tags. | ||
* This function uses a regular expression to find and remove all | ||
* occurrences of <script>...</script> tags and any content within them. | ||
* | ||
* @param {string} input The HTML string to be sanitized. | ||
* @return {string} The sanitized HTML string. | ||
*/ | ||
export function sanitize(input) { | ||
const window = new JSDOM('').window; | ||
const purify = DOMPurify(window); | ||
return purify.sanitize(input); | ||
} | ||
|
||
export default sanitize; |
Oops, something went wrong.