1
0
mirror of https://github.com/uetchy/namae.git synced 2025-08-20 01:48:12 +09:00

fix: properly validate URL

This commit is contained in:
2020-06-11 22:00:16 +09:00
parent b8ce81b276
commit 4232d0435d
11 changed files with 45 additions and 19 deletions

View File

@@ -10,6 +10,7 @@
"dependencies": {
"node-fetch": "^2.6.0",
"npm-name": "^6.0.0",
"validator": "^13.1.0",
"whois-json": "^2.0.4"
},
"devDependencies": {

View File

@@ -1,3 +1,4 @@
import isURL from 'validator/lib/isURL';
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
export default async function handler(
@@ -10,12 +11,8 @@ export default async function handler(
return sendError(res, new Error('no query given'));
}
if (
!/^[(http(s)?)://(www.)?a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/.test(
query,
)
) {
return sendError(res, new Error('Invalid characters'));
if (!isURL(query)) {
return sendError(res, new Error('Invalid URL: ' + query));
}
try {