Lookup location for payload IPs. Removed hostname from session id.

This commit is contained in:
Mike Cao 2025-02-21 18:11:52 -08:00
parent e060f2b240
commit 0aad3d8e05
2 changed files with 4 additions and 4 deletions

View file

@ -87,7 +87,7 @@ export async function POST(request: Request) {
return forbidden();
}
const sessionId = uuid(websiteId, hostname, ip, userAgent);
const sessionId = uuid(websiteId, ip, userAgent);
// Find session
if (!clickhouse.enabled && !cache?.sessionId) {

View file

@ -86,13 +86,13 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
return Buffer.from(s, 'latin1').toString('utf-8');
}
export async function getLocation(ip: string = '', headers: Headers) {
export async function getLocation(ip: string = '', headers: Headers, hasPayloadIP: boolean) {
// Ignore local ips
if (await isLocalhost(ip)) {
return;
}
if (!process.env.SKIP_LOCATION_HEADERS) {
if (!hasPayloadIP && !process.env.SKIP_LOCATION_HEADERS) {
// Cloudflare headers
if (headers.get('cf-ipcountry')) {
const country = decodeHeader(headers.get('cf-ipcountry'));
@ -147,7 +147,7 @@ export async function getLocation(ip: string = '', headers: Headers) {
export async function getClientInfo(request: Request, payload: Record<string, any>) {
const userAgent = payload?.userAgent || request.headers.get('user-agent');
const ip = payload?.ip || getIpAddress(request.headers);
const location = await getLocation(ip, request.headers);
const location = await getLocation(ip, request.headers, !!payload?.ip);
const country = payload?.userAgent || location?.country;
const subdivision1 = location?.subdivision1;
const subdivision2 = location?.subdivision2;