Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Removed hostname lookup.

Mike Caoe074394b134f
diff --git a/src/pages/api/send.ts b/src/pages/api/send.ts
index cf3004f3f..1698d858d 100644
--- a/src/pages/api/send.ts
+++ b/src/pages/api/send.ts
@@ -1,4 +1,3 @@
-import { Resolver } from 'dns/promises';
import ipaddr from 'ipaddr.js';
import isbot from 'isbot';
import { COLLECTION_TYPE, HOSTNAME_REGEX } from 'lib/constants';
@@ -78,14 +77,14 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
return ok(res);
}
- const { type, payload } = req.body;
-
await useValidate(schema, req, res);
- if (await hasBlockedIp(req)) {
+ if (hasBlockedIp(req)) {
return forbidden(res);
}
+ const { type, payload } = req.body;
+
const { url, referrer, name: eventName, data: eventData, title: pageTitle } = payload;
await useSession(req, res);
@@ -143,28 +142,16 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
return methodNotAllowed(res);
};
-async function hasBlockedIp(req: NextApiRequestCollect) {
+function hasBlockedIp(req: NextApiRequestCollect) {
const ignoreIps = process.env.IGNORE_IP;
- const ignoreHostnames = process.env.IGNORE_HOSTNAME;
- if (ignoreIps || ignoreHostnames) {
+ if (ignoreIps) {
const ips = [];
if (ignoreIps) {
ips.push(...ignoreIps.split(',').map(n => n.trim()));
}
- if (ignoreHostnames) {
- const resolver = new Resolver();
- const promises = ignoreHostnames
- .split(',')
- .map(n => resolver.resolve4(n.trim()).catch(() => {}));
-
- await Promise.all(promises).then(resolvedIps => {
- ips.push(...resolvedIps.filter(n => n).flatMap(n => n as string[]));
- });
- }
-
const clientIp = getIpAddress(req);
return ips.find(ip => {
@@ -177,8 +164,8 @@ async function hasBlockedIp(req: NextApiRequestCollect) {
if (addr.kind() === range[0].kind() && addr.match(range)) return true;
}
-
- return false;
});
}
+
+ return false;
}