Check the hostname value for legality to eliminate dirty data

Check the hostname value for legality to eliminate dirty data
This commit is contained in:
榆木 2023-07-13 12:27:38 +08:00 committed by GitHub
parent 7bfbe26485
commit 35cf149876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,6 +30,13 @@ export async function findSession(req: NextApiRequestCollect) {
// Verify payload
const { website: websiteId, hostname, screen, language } = payload;
// Check the hostname value for legality to eliminate dirty data
const validHostnameRegex = /^[\w-.]+$/;
if (!validHostnameRegex.test(hostname)) {
throw new Error('Invalid hostname.');
}
if (!validate(websiteId)) {
throw new Error('Invalid website ID.');
}