Fighting spam :/
This commit is contained in:
parent
c37101a5d2
commit
f0d05ea756
|
@ -1,9 +1,22 @@
|
||||||
const validateNpmPackageName = require("validate-npm-package-name");
|
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.
|
* Reject requests for invalid npm package names.
|
||||||
*/
|
*/
|
||||||
function validatePackageName(req, res, next) {
|
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;
|
const errors = validateNpmPackageName(req.packageName).errors;
|
||||||
|
|
||||||
if (errors) {
|
if (errors) {
|
||||||
|
|
Loading…
Reference in New Issue