forked from woocommerce/woocommerce-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix use of sanitizeHTML (woocommerce#7231)
* Remove object from sanitizeHTML return value * Import sanitizeHTML from utils * Fix dangerously set inner HTML format * Update package-lock * Update package-lock * Update package-lock * Update @types/dompurify version Co-authored-by: Thomas Roberts <[email protected]>
- Loading branch information
Showing
4 changed files
with
42,099 additions
and
65,628 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
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,27 +1,20 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import DOMPurify from 'dompurify'; | ||
|
||
type sanitizedHTMLObject = { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
__html: string; | ||
}; | ||
import { sanitize } from 'dompurify'; | ||
|
||
const ALLOWED_TAGS = [ 'a', 'b', 'em', 'i', 'strong', 'p', 'br' ]; | ||
const ALLOWED_ATTR = [ 'target', 'href', 'rel', 'name', 'download' ]; | ||
|
||
export const sanitizeHTML = ( | ||
html: string, | ||
config?: { tags?: typeof ALLOWED_TAGS; attr?: typeof ALLOWED_ATTR } | ||
): sanitizedHTMLObject => { | ||
) => { | ||
const tagsValue = config?.tags || ALLOWED_TAGS; | ||
const attrValue = config?.attr || ALLOWED_ATTR; | ||
|
||
return { | ||
__html: DOMPurify.sanitize( html, { | ||
ALLOWED_TAGS: tagsValue, | ||
ALLOWED_ATTR: attrValue, | ||
} ), | ||
}; | ||
return sanitize( html, { | ||
ALLOWED_TAGS: tagsValue, | ||
ALLOWED_ATTR: attrValue, | ||
} ); | ||
}; |
Oops, something went wrong.