Skip to content

Commit 0aad3d8

Browse files
committed
Lookup location for payload IPs. Removed hostname from session id.
1 parent e060f2b commit 0aad3d8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/app/api/send/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export async function POST(request: Request) {
8787
return forbidden();
8888
}
8989

90-
const sessionId = uuid(websiteId, hostname, ip, userAgent);
90+
const sessionId = uuid(websiteId, ip, userAgent);
9191

9292
// Find session
9393
if (!clickhouse.enabled && !cache?.sessionId) {

src/lib/detect.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
8686
return Buffer.from(s, 'latin1').toString('utf-8');
8787
}
8888

89-
export async function getLocation(ip: string = '', headers: Headers) {
89+
export async function getLocation(ip: string = '', headers: Headers, hasPayloadIP: boolean) {
9090
// Ignore local ips
9191
if (await isLocalhost(ip)) {
9292
return;
9393
}
9494

95-
if (!process.env.SKIP_LOCATION_HEADERS) {
95+
if (!hasPayloadIP && !process.env.SKIP_LOCATION_HEADERS) {
9696
// Cloudflare headers
9797
if (headers.get('cf-ipcountry')) {
9898
const country = decodeHeader(headers.get('cf-ipcountry'));
@@ -147,7 +147,7 @@ export async function getLocation(ip: string = '', headers: Headers) {
147147
export async function getClientInfo(request: Request, payload: Record<string, any>) {
148148
const userAgent = payload?.userAgent || request.headers.get('user-agent');
149149
const ip = payload?.ip || getIpAddress(request.headers);
150-
const location = await getLocation(ip, request.headers);
150+
const location = await getLocation(ip, request.headers, !!payload?.ip);
151151
const country = payload?.userAgent || location?.country;
152152
const subdivision1 = location?.subdivision1;
153153
const subdivision2 = location?.subdivision2;

0 commit comments

Comments
 (0)