Skip to content

Commit 9561d97

Browse files
committed
Merge remote-tracking branch 'origin/rm-tracking-cookie' into pr-20251208
2 parents f5f0ddf + 7b6aec2 commit 9561d97

File tree

25 files changed

+839
-192
lines changed

25 files changed

+839
-192
lines changed

src/packages/conat/core/server.ts

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,52 @@ cd packages/server
2828
*/
2929

3030
import type { ConnectionStats, ServerInfo } from "./types";
31+
32+
import { delay } from "awaiting";
33+
import { EventEmitter } from "events";
34+
import { throttle } from "lodash";
35+
import { Server } from "socket.io";
36+
37+
import { getClientIpAddress } from "@cocalc/util/get-client-ip-address";
38+
import { getLogger } from "@cocalc/conat/client";
39+
import { UsageMonitor } from "@cocalc/conat/monitor/usage";
40+
import { type ConatSocketServer } from "@cocalc/conat/socket";
3141
import {
3242
isValidSubject,
3343
isValidSubjectWithoutWildcards,
3444
} from "@cocalc/conat/util";
35-
import { Server } from "socket.io";
36-
import { delay } from "awaiting";
45+
import { once, until } from "@cocalc/util/async-utils";
46+
import { is_array } from "@cocalc/util/misc";
47+
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
48+
import { Metrics } from "../types";
3749
import {
38-
ConatError,
39-
connect,
4050
Client,
4151
type ClientOptions,
52+
ConatError,
53+
connect,
4254
MAX_INTEREST_TIMEOUT,
4355
} from "./client";
44-
import {
45-
RESOURCE,
46-
MAX_CONNECTIONS_PER_USER,
47-
MAX_CONNECTIONS,
48-
MAX_PAYLOAD,
49-
MAX_SUBSCRIPTIONS_PER_CLIENT,
50-
MAX_SUBSCRIPTIONS_PER_HUB,
51-
} from "./constants";
52-
import { Patterns } from "./patterns";
53-
import { is_array } from "@cocalc/util/misc";
54-
import { UsageMonitor } from "@cocalc/conat/monitor/usage";
55-
import { once, until } from "@cocalc/util/async-utils";
5656
import {
5757
clusterLink,
5858
type ClusterLink,
5959
clusterStreams,
6060
type ClusterStreams,
61-
trimClusterStreams,
6261
createClusterPersistServer,
62+
trimClusterStreams,
6363
Interest,
6464
hashInterest,
6565
} from "./cluster";
66-
import { type ConatSocketServer } from "@cocalc/conat/socket";
67-
import { throttle } from "lodash";
68-
import { getLogger } from "@cocalc/conat/client";
69-
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
70-
import { type SysConatServer, sysApiSubject, sysApi } from "./sys";
66+
import {
67+
MAX_CONNECTIONS,
68+
MAX_CONNECTIONS_PER_USER,
69+
MAX_PAYLOAD,
70+
MAX_SUBSCRIPTIONS_PER_CLIENT,
71+
MAX_SUBSCRIPTIONS_PER_HUB,
72+
RESOURCE,
73+
} from "./constants";
74+
import { Patterns } from "./patterns";
7175
import { forkedConatServer } from "./start-server";
72-
import { EventEmitter } from "events";
73-
import { Metrics } from "../types";
76+
import { sysApi, sysApiSubject, type SysConatServer } from "./sys";
7477

7578
const logger = getLogger("conat:core:server");
7679

@@ -1564,27 +1567,7 @@ export function randomChoice(v: Set<string>): string {
15641567

15651568
// See https://socket.io/how-to/get-the-ip-address-of-the-client
15661569
function getAddress(socket) {
1567-
const header = socket.handshake.headers["forwarded"];
1568-
if (header) {
1569-
for (const directive of header.split(",")[0].split(";")) {
1570-
if (directive.startsWith("for=")) {
1571-
return directive.substring(4);
1572-
}
1573-
}
1574-
}
1575-
1576-
let addr = socket.handshake.headers["x-forwarded-for"]?.split(",")?.[0];
1577-
if (addr) {
1578-
return addr;
1579-
}
1580-
for (const other of ["cf-connecting-ip", "fastly-client-ip"]) {
1581-
addr = socket.handshake.headers[other];
1582-
if (addr) {
1583-
return addr;
1584-
}
1585-
}
1586-
1587-
return socket.handshake.address;
1570+
return getClientIpAddress(socket.handshake) ?? socket.handshake.address;
15881571
}
15891572

15901573
export function updateInterest(update: InterestUpdate, interest: Interest) {

src/packages/frontend/account/settings/email-address-setting.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const EmailAddressSetting = ({
7777
return;
7878
}
7979
try {
80-
// anonymouse users will get the "welcome" email
80+
// anonymous users will get the "welcome" email
8181
await webapp_client.account_client.send_verification_email(!is_anonymous);
8282
} catch (error) {
8383
const err_msg = `Problem sending welcome email: ${error}`;

src/packages/frontend/user-tracking.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,33 @@
77
// client code doesn't have to import webapp_client everywhere, and we can
88
// completely change this if we want.
99

10-
import { query, server_time } from "./frame-editors/generic/client";
11-
import { analytics_cookie_name as analytics, uuid } from "@cocalc/util/misc";
12-
import { redux } from "./app-framework";
10+
import { redux } from "@cocalc/frontend/app-framework";
11+
import {
12+
query,
13+
server_time,
14+
} from "@cocalc/frontend/frame-editors/generic/client";
15+
import { get_cookie } from "@cocalc/frontend/misc";
16+
import { webapp_client } from "@cocalc/frontend/webapp-client";
17+
import { uuid } from "@cocalc/util/misc";
1318
import { version } from "@cocalc/util/smc-version";
14-
import { get_cookie } from "./misc";
15-
import { webapp_client } from "./webapp-client";
19+
20+
import { ANALYTICS_COOKIE_NAME } from "@cocalc/util/consts";
1621

1722
export async function log(eventName: string, payload: any): Promise<void> {
1823
const central_log = {
1924
id: uuid(),
2025
event: `webapp-${eventName}`,
2126
value: {
2227
account_id: redux.getStore("account")?.get("account_id"),
23-
analytics_cookie: get_cookie(analytics),
28+
analytics_cookie: get_cookie(ANALYTICS_COOKIE_NAME),
2429
cocalc_version: version,
2530
...payload,
2631
},
2732
time: server_time(),
2833
};
34+
2935
try {
30-
await query({
31-
query: {
32-
central_log,
33-
},
34-
});
36+
await query({ query: { central_log } });
3537
} catch (err) {
3638
console.warn("WARNING: Failed to write log event -- ", central_log);
3739
}

src/packages/hub/analytics-script.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
* e.g. this filters the SSO auth pages, which are uninteresting referrals
1616
*/
1717

18-
// variable PREFIX, NAME, DOMAIN and ID are injected in the hub's http server
19-
declare var NAME, ID, DOMAIN, PREFIX, window, document;
18+
// variable PREFIX, NAME, DOMAIN, ID, and ANALYTICS_ENABLED are injected in the hub's http server
19+
declare var NAME, ID, DOMAIN, PREFIX, ANALYTICS_ENABLED, window, document;
2020

21-
// write cookie. it would be cool to set this via the http request itself,
22-
// but for reasons I don't know it doesn't work across subdomains.
23-
const maxage = 7 * 24 * 60 * 60; // 7 days
24-
document.cookie = `${NAME}=${ID}; path=/; domain=${DOMAIN}; max-age=${maxage}`;
21+
// write cookie only if analytics is enabled (for privacy in cookieless mode)
22+
if (ANALYTICS_ENABLED) {
23+
// it would be cool to set this via the http request itself,
24+
// but for reasons I don't know it doesn't work across subdomains.
25+
const maxage = 7 * 24 * 60 * 60; // 7 days
26+
document.cookie = `${NAME}=${ID}; path=/; domain=${DOMAIN}; max-age=${maxage}`;
27+
}
2528

2629
const { href, protocol, host, pathname } = window.location;
2730

0 commit comments

Comments
 (0)