blob: 972f9b79ad6120b639c1bd6a7d9ce6a3cc77681a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import { URL } from 'url';
import { ALLOWED_PROTOCOLS } from '../config';
const debug = require('debug')('Ferdi:Helpers:url');
export function isValidExternalURL(url) {
let parsedUrl;
try {
parsedUrl = new URL(url);
} catch (_) {
return false;
}
const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol);
debug('protocol check is', isAllowed, 'for:', url);
return isAllowed;
}
|