Fix prevent-innerHTML scriptlet

This commit is contained in:
Raymond Hill 2025-03-24 07:33:21 -04:00
parent 07a4a6a35d
commit 0c8de6b550
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -48,10 +48,10 @@ export function preventInnerHTML(
const matcher = safe.initPattern(pattern, { canNegate: true });
const current = safe.Object_getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
if ( current === undefined ) { return; }
const shouldPreventSet = a => {
const shouldPreventSet = (elem, a) => {
if ( selector !== '' ) {
if ( typeof this.matches === 'function' === false ) { return false; }
if ( this.matches(selector) === false ) { return false; }
if ( typeof elem.matches !== 'function' ) { return false; }
if ( elem.matches(selector) === false ) { return false; }
}
return safe.testPattern(matcher, a);
};
@ -62,7 +62,7 @@ export function preventInnerHTML(
: current.value;
},
set: function(a) {
if ( shouldPreventSet(a) ) {
if ( shouldPreventSet(this, a) ) {
safe.uboLog(logPrefix, 'Prevented');
} else if ( current.set ) {
current.set.call(this, a);