feat: add media upload to news editor with drag-drop, paste, and file picker

Upload images/videos directly to server from editor. DOMPurify video
sanitization, XSS protection, upload cancellation on unmount.
This commit is contained in:
Fringg
2026-03-23 11:58:18 +03:00
parent 8d994f75d9
commit 723591e5c3
8 changed files with 324 additions and 23 deletions

View File

@@ -99,6 +99,26 @@ DOMPurify.addHook('afterSanitizeAttributes', (node) => {
}
});
// Hook: validate <video> src — only allow http/https URLs
DOMPurify.addHook('afterSanitizeAttributes', (node) => {
if (node.tagName === 'VIDEO') {
const src = node.getAttribute('src') ?? '';
try {
const url = new URL(src);
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
node.remove();
return;
}
} catch {
node.remove();
return;
}
// Force safe defaults
node.setAttribute('controls', '');
node.setAttribute('preload', 'metadata');
}
});
/**
* Strict allowlist of tags and attributes for article content.
* Using ALLOWED_TAGS / ALLOWED_ATTR instead of ADD_TAGS / ADD_ATTR
@@ -145,6 +165,7 @@ const SANITIZE_CONFIG = {
'sup',
'small',
'img',
'video',
// Embed (validated by afterSanitizeAttributes hook)
'iframe',
'figure',
@@ -164,6 +185,9 @@ const SANITIZE_CONFIG = {
'start',
'reversed',
'type',
// video-specific
'controls',
'preload',
// iframe-specific (validated by hook)
'frameborder',
'allowfullscreen',