diff --git a/server/ingestLogs.js b/server/ingestLogs.js index f4f6f16..114695e 100644 --- a/server/ingestLogs.js +++ b/server/ingestLogs.js @@ -3,6 +3,7 @@ const startOfDay = require("date-fns/start_of_day"); const addDays = require("date-fns/add_days"); const db = require("./utils/redis"); +const isValidPackageName = require("./utils/isValidPackageName"); const parsePackageURL = require("./utils/parsePackageURL"); const CloudflareAPI = require("./CloudflareAPI"); @@ -67,7 +68,7 @@ function computeCounters(stream) { const url = parsePackageURL(parseURL(clientRequest.uri).pathname); const packageName = url && url.packageName; - if (packageName) { + if (packageName && isValidPackageName(packageName)) { incr( `stats-packageRequests-${dayKey}`, packageName, diff --git a/server/utils/parsePackageURL.js b/server/utils/parsePackageURL.js index 4a47694..a2f8a41 100644 --- a/server/utils/parsePackageURL.js +++ b/server/utils/parsePackageURL.js @@ -1,7 +1,5 @@ const url = require("url"); -const isValidPackageName = require("./isValidPackageName"); - const packageURLFormat = /^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+))?(\/.*)?$/; function decodeParam(param) { @@ -18,7 +16,6 @@ function decodeParam(param) { function parsePackageURL(originalURL) { const { pathname, search, query } = url.parse(originalURL, true); - const match = packageURLFormat.exec(pathname); // Disallow invalid URL formats. @@ -27,12 +24,6 @@ function parsePackageURL(originalURL) { } const packageName = match[1]; - - // Disallow invalid npm package names. - if (!isValidPackageName(packageName)) { - return null; - } - const packageVersion = decodeParam(match[2]) || "latest"; const filename = decodeParam(match[3]);