You can configure DOMPurify to allow the trackingfeature attribute while retaining its sanitization for other attributes.
// Configure DOMPurify to allow the "trackingfeature" attribute with colons
DOMPurify.sanitize(dirtyHTML, {
ADD_ATTR: ['trackingfeature'], // Explicitly allow the "trackingfeature" attribute
ALLOW_UNKNOWN_PROTOCOLS: true // Allow unknown protocols like "aem:"
});This configuration ensures that the trackingfeature attribute is not stripped out during sanitization, and it allows colons in the attribute value by enabling ALLOW_UNKNOWN_PROTOCOLS. However, be cautious when enabling ALLOW_UNKNOWN_PROTOCOLS, as it could introduce security risks if misused.
Alternatively, you can use a hook to bypass sanitization for this specific attribute:
DOMPurify.addHook('uponSanitizeAttribute', function(node, data) {
if (data.attrName === 'trackingfeature') {
data.forceKeepAttr = true;
}
});This approach should ensures that the trackingfeature attribute is preserved exactly as it is, without being modified or removed by DOMPurify.