Better URL validation
This commit is contained in:
parent
7ea83415e8
commit
3e632dd91f
11
app.js
11
app.js
@ -391,14 +391,13 @@ app.post('/dashboard/link', async (req, res) => {
|
||||
|
||||
if (name == null || url == null) return res.jsonp({ error: 'Missing parameters!' })
|
||||
if (name.length > 120) return res.jsonp({ error: 'Only 120 characters are allowed in the name.' })
|
||||
if (name.indexOf('<') !== -1 || name.indexOf('>') !== -1) return res.jsonp({ error: 'HTML tags are forbidden!' })
|
||||
if (name.length < 3) return res.jsonp({ error: 'Minimum name length is 3 characters.' })
|
||||
if (name.indexOf('<') !== -1 || name.indexOf('>') !== -1 ||
|
||||
url.indexOf('<') !== -1 || url.indexOf('>') !== -1) return res.jsonp({ error: 'HTML tags are forbidden!' })
|
||||
|
||||
// Validate URL
|
||||
try {
|
||||
URL.parse(url)
|
||||
} catch (e) {
|
||||
return res.jsonp({ error: 'Invalid URL!' })
|
||||
}
|
||||
let a = URL.parse(url)
|
||||
if (a.protocol === null || a.host === null || a.slashes !== true) return res.jsonp({ error: 'Invalid URL!' })
|
||||
|
||||
// Checks
|
||||
let db = await dbPromise
|
||||
|
Reference in New Issue
Block a user