FE Sandbox: Fix innerHTML distortion causing issues with DOMPurify inner works (#87117)

* FE Sandbox: Fix innerHTML distortion causing issues with DOMPurify inner works

* Add a comment explaining the fix
This commit is contained in:
Esteban Beltran
2024-05-02 11:17:04 +02:00
committed by GitHub
parent a59e7e14b1
commit 9f5ab38477
@@ -204,7 +204,10 @@ function distortInnerHTML(distortions: DistortionMap) {
const pluginId = meta.id;
return function innerHTMLDistortion(this: HTMLElement, ...args: string[]) {
for (const arg of args) {
const lowerCase = arg?.toLowerCase() || '';
// NOTE: DOMPurify anti-tamper mechanism requires us to clone the string
// calling any method whatsoever on a string will cause the string to be tampered
// and DOMPurify will return empty strings
const lowerCase = String(arg || '').toLowerCase();
for (const forbiddenElement of forbiddenElements) {
if (lowerCase.includes('<' + forbiddenElement)) {
logWarning(`Plugin ${pluginId} tried to set ${forbiddenElement} in innerHTML`, {
@@ -223,7 +226,7 @@ function distortInnerHTML(distortions: DistortionMap) {
}
if (isFunction(originalMethod)) {
originalMethod.apply(this, args);
return originalMethod.apply(this, args);
}
};
}