Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sanitize_html.js « services « rich_content_editor « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 486d88466b7c88cdc68eb520ef74666f021fcac9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import createSanitizer from 'dompurify';
import { getURLOrigin } from '~/lib/utils/url_utility';
import { ALLOWED_VIDEO_ORIGINS } from '../constants';

const sanitizer = createSanitizer(window);
const ADD_TAGS = ['iframe'];

sanitizer.addHook('uponSanitizeElement', (node) => {
  if (node.tagName !== 'IFRAME') {
    return;
  }

  const origin = getURLOrigin(node.getAttribute('src'));

  if (!ALLOWED_VIDEO_ORIGINS.includes(origin)) {
    node.remove();
  }
});

const sanitize = (content) => sanitizer.sanitize(content, { ADD_TAGS });

export default sanitize;