mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-08-06 04:37:37 +00:00
Merge pull request #4905 from G-Ambatte/fixSafeHTML
Fix safeHTML attribute check
This commit is contained in:
@@ -32,12 +32,12 @@ function safeHTML(htmlString) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check remaining elements for blacklisted attributes
|
// Check remaining elements for blacklisted attributes
|
||||||
for (const attribute of element.attributes){
|
[...element.attributes].forEach((attribute)=>{
|
||||||
if(blacklistAttrs.some((test)=>{return test(attribute);})) {
|
if(blacklistAttrs.some((test)=>{return test(attribute);})) {
|
||||||
element.removeAttribute(attribute.localName);
|
element.removeAttribute(attribute.name);
|
||||||
break;
|
return;
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return div.innerHTML;
|
return div.innerHTML;
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ test('Javascript via inline event handler - onMouseOver', function() {
|
|||||||
expect(rendered).toBe('<div>Hover over me</div>');
|
expect(rendered).toBe('<div>Hover over me</div>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Javascript via multiple inline event handlers - onClick + onMouseOver', function() {
|
||||||
|
const source = `<div onclick="alert('This is a JavaScript injection via inline event handler')" onmouseover="alert('This is a JavaScript injection via inline event handler')">Hover over or Click me</div>`;
|
||||||
|
const rendered = safeHTML(source);
|
||||||
|
expect(rendered).toBe('<div>Hover over or Click me</div>');
|
||||||
|
});
|
||||||
|
|
||||||
test('Javascript via data attribute', function() {
|
test('Javascript via data attribute', function() {
|
||||||
const source = `<div data-code="javascript:alert('This is a JavaScript injection via data attribute')">Test</div>`;
|
const source = `<div data-code="javascript:alert('This is a JavaScript injection via data attribute')">Test</div>`;
|
||||||
const rendered = safeHTML(source);
|
const rendered = safeHTML(source);
|
||||||
|
|||||||
Reference in New Issue
Block a user