Don't check package name when parsing

This commit is contained in:
Michael Jackson 2018-05-25 20:30:53 -04:00
parent c0e0f899d2
commit bca5722eae
2 changed files with 2 additions and 10 deletions

View File

@ -3,6 +3,7 @@ const startOfDay = require("date-fns/start_of_day");
const addDays = require("date-fns/add_days"); const addDays = require("date-fns/add_days");
const db = require("./utils/redis"); const db = require("./utils/redis");
const isValidPackageName = require("./utils/isValidPackageName");
const parsePackageURL = require("./utils/parsePackageURL"); const parsePackageURL = require("./utils/parsePackageURL");
const CloudflareAPI = require("./CloudflareAPI"); const CloudflareAPI = require("./CloudflareAPI");
@ -67,7 +68,7 @@ function computeCounters(stream) {
const url = parsePackageURL(parseURL(clientRequest.uri).pathname); const url = parsePackageURL(parseURL(clientRequest.uri).pathname);
const packageName = url && url.packageName; const packageName = url && url.packageName;
if (packageName) { if (packageName && isValidPackageName(packageName)) {
incr( incr(
`stats-packageRequests-${dayKey}`, `stats-packageRequests-${dayKey}`,
packageName, packageName,

View File

@ -1,7 +1,5 @@
const url = require("url"); const url = require("url");
const isValidPackageName = require("./isValidPackageName");
const packageURLFormat = /^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/; const packageURLFormat = /^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/;
function decodeParam(param) { function decodeParam(param) {
@ -18,7 +16,6 @@ function decodeParam(param) {
function parsePackageURL(originalURL) { function parsePackageURL(originalURL) {
const { pathname, search, query } = url.parse(originalURL, true); const { pathname, search, query } = url.parse(originalURL, true);
const match = packageURLFormat.exec(pathname); const match = packageURLFormat.exec(pathname);
// Disallow invalid URL formats. // Disallow invalid URL formats.
@ -27,12 +24,6 @@ function parsePackageURL(originalURL) {
} }
const packageName = match[1]; const packageName = match[1];
// Disallow invalid npm package names.
if (!isValidPackageName(packageName)) {
return null;
}
const packageVersion = decodeParam(match[2]) || "latest"; const packageVersion = decodeParam(match[2]) || "latest";
const filename = decodeParam(match[3]); const filename = decodeParam(match[3]);