mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add option to forbid external images
This commit is contained in:
@ -296,6 +296,25 @@ DOMPurify.addHook('uponSanitizeAttribute', (_, data, config) => {
|
||||
}
|
||||
});
|
||||
|
||||
DOMPurify.addHook('uponSanitizeElement', (node, _, config) => {
|
||||
if (!config['MESSAGE_SANITIZE']) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (node.tagName) {
|
||||
case 'IMG': {
|
||||
const isExternalUrl = (url) => (url.indexOf('://') > 0 || url.indexOf('//') === 0) && !url.startsWith(window.location.origin);
|
||||
const src = node.getAttribute('src');
|
||||
|
||||
if (power_user.forbid_external_images && isExternalUrl(src)) {
|
||||
console.warn('External image blocked', src);
|
||||
node.remove();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// API OBJECT FOR EXTERNAL WIRING
|
||||
window['SillyTavern'] = {};
|
||||
|
||||
|
Reference in New Issue
Block a user