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