We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c37101a commit f0d05eaCopy full SHA for f0d05ea
modules/middleware/validatePackageName.js
@@ -1,9 +1,22 @@
1
const validateNpmPackageName = require("validate-npm-package-name");
2
3
+const hexValue = /^[a-f0-9]+$/i;
4
+
5
+function isHash(value) {
6
+ return value.length === 32 && hexValue.test(value);
7
+}
8
9
/**
10
* Reject requests for invalid npm package names.
11
*/
12
function validatePackageName(req, res, next) {
13
+ if (isHash(req.packageName)) {
14
+ return res
15
+ .status(403)
16
+ .type("text")
17
+ .send(`Invalid package name "${req.packageName}" (cannot be a hash)`);
18
+ }
19
20
const errors = validateNpmPackageName(req.packageName).errors;
21
22
if (errors) {
0 commit comments