parse server user-agents better
This commit is contained in:
@@ -23,7 +23,7 @@ export function parseUserAgent(ua?: string | null) {
|
|||||||
} as const;
|
} as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userAgentServerList: string[] = [
|
const userAgentServerList = [
|
||||||
// Node.js libraries
|
// Node.js libraries
|
||||||
'node',
|
'node',
|
||||||
'node-fetch',
|
'node-fetch',
|
||||||
@@ -35,6 +35,8 @@ const userAgentServerList: string[] = [
|
|||||||
// Python libraries
|
// Python libraries
|
||||||
'python-requests',
|
'python-requests',
|
||||||
'python-urllib',
|
'python-urllib',
|
||||||
|
'aiohttp',
|
||||||
|
'python',
|
||||||
|
|
||||||
// Ruby libraries
|
// Ruby libraries
|
||||||
'Faraday',
|
'Faraday',
|
||||||
@@ -69,13 +71,13 @@ const userAgentServerList: string[] = [
|
|||||||
|
|
||||||
function isServer(userAgent: string) {
|
function isServer(userAgent: string) {
|
||||||
const match = userAgentServerList.some((server) =>
|
const match = userAgentServerList.some((server) =>
|
||||||
userAgent.includes(server)
|
userAgent.toLowerCase().includes(server.toLowerCase())
|
||||||
);
|
);
|
||||||
if (match) {
|
if (match) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !!userAgent.match(/^[^\s]+\/[\d.]+$/);
|
return !!userAgent.match(/^([^\s]+\/[\d.]+\s*)+$/);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDevice(ua: string) {
|
export function getDevice(ua: string) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
toISOString,
|
toISOString,
|
||||||
} from '@openpanel/common';
|
} from '@openpanel/common';
|
||||||
import type { IServiceCreateEventPayload, IServiceEvent } from '@openpanel/db';
|
import type { IServiceCreateEventPayload, IServiceEvent } from '@openpanel/db';
|
||||||
import { createEvent, getProfileIdCached } from '@openpanel/db';
|
import { createEvent } from '@openpanel/db';
|
||||||
import { getLastScreenViewFromProfileId } from '@openpanel/db/src/services/event.service';
|
import { getLastScreenViewFromProfileId } from '@openpanel/db/src/services/event.service';
|
||||||
import { eventsQueue, findJobByPrefix, sessionsQueue } from '@openpanel/queue';
|
import { eventsQueue, findJobByPrefix, sessionsQueue } from '@openpanel/queue';
|
||||||
import type {
|
import type {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function parseUserAgent(ua?: string | null) {
|
|||||||
} as const;
|
} as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userAgentServerList: string[] = [
|
const userAgentServerList = [
|
||||||
// Node.js libraries
|
// Node.js libraries
|
||||||
'node',
|
'node',
|
||||||
'node-fetch',
|
'node-fetch',
|
||||||
@@ -35,6 +35,8 @@ const userAgentServerList: string[] = [
|
|||||||
// Python libraries
|
// Python libraries
|
||||||
'python-requests',
|
'python-requests',
|
||||||
'python-urllib',
|
'python-urllib',
|
||||||
|
'aiohttp',
|
||||||
|
'python',
|
||||||
|
|
||||||
// Ruby libraries
|
// Ruby libraries
|
||||||
'Faraday',
|
'Faraday',
|
||||||
@@ -69,13 +71,13 @@ const userAgentServerList: string[] = [
|
|||||||
|
|
||||||
function isServer(userAgent: string) {
|
function isServer(userAgent: string) {
|
||||||
const match = userAgentServerList.some((server) =>
|
const match = userAgentServerList.some((server) =>
|
||||||
userAgent.includes(server)
|
userAgent.toLowerCase().includes(server.toLowerCase())
|
||||||
);
|
);
|
||||||
if (match) {
|
if (match) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !!userAgent.match(/^[^\s]+\/[\d.]+$/);
|
return !!userAgent.match(/^([^\s]+\/[\d.]+\s*)+$/);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDevice(ua: string) {
|
export function getDevice(ua: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user