Fighting spam :/

This commit is contained in:
Michael Jackson 2018-09-03 09:19:24 -07:00
parent c37101a5d2
commit f0d05ea756
1 changed files with 13 additions and 0 deletions

View File

@ -1,9 +1,22 @@
const validateNpmPackageName = require("validate-npm-package-name");
const hexValue = /^[a-f0-9]+$/i;
function isHash(value) {
return value.length === 32 && hexValue.test(value);
}
/**
* Reject requests for invalid npm package names.
*/
function validatePackageName(req, res, next) {
if (isHash(req.packageName)) {
return res
.status(403)
.type("text")
.send(`Invalid package name "${req.packageName}" (cannot be a hash)`);
}
const errors = validateNpmPackageName(req.packageName).errors;
if (errors) {