Skip to content

Commit 8dff5c1

Browse files
cherkanovartclaude
andauthored
fix: hash emails before sending as PostHog distinct_id (#2002)
Use SHA-256 hash of email instead of raw email for PostHog distinct_id across cli, compiler, and new-compiler packages to avoid sending PII. Closes ENG-378 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 716f0df commit 8dff5c1

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.changeset/fix-emails-posthog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"lingo.dev": patch
3+
"@lingo.dev/_compiler": patch
4+
"@lingo.dev/compiler": patch
5+
---
6+
7+
fix: hash emails before sending as PostHog distinct_id

packages/cli/src/cli/utils/observability.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pkg from "node-machine-id";
22
const { machineIdSync } = pkg;
33
import https from "https";
4+
import crypto from "crypto";
45
import { getOrgId } from "./org-id";
56

67
const POSTHOG_API_KEY = "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk";
@@ -17,8 +18,9 @@ function determineDistinctId(email: string | null | undefined): {
1718
const orgId = getOrgId();
1819

1920
if (email) {
21+
const hashedEmail = crypto.createHash("sha256").update(email).digest("hex");
2022
return {
21-
distinct_id: email,
23+
distinct_id: hashedEmail,
2224
distinct_id_source: "email",
2325
org_id: orgId,
2426
};

packages/compiler/src/utils/observability.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as machineIdLib from "node-machine-id";
2+
import crypto from "crypto";
23
import { getRc } from "./rc";
34
import { getOrgId } from "./org-id";
45

@@ -64,8 +65,9 @@ async function getDistinctId(): Promise<{
6465
const email = await tryGetEmail();
6566

6667
if (email) {
68+
const hashedEmail = crypto.createHash("sha256").update(email).digest("hex");
6769
return {
68-
distinct_id: email,
70+
distinct_id: hashedEmail,
6971
distinct_id_source: "email",
7072
org_id: orgId,
7173
};

packages/new-compiler/src/utils/observability.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as machineIdLib from "node-machine-id";
2+
import crypto from "crypto";
23
import { getRc } from "./rc";
34
import { getOrgId } from "./org-id";
45
import { TRACKING_VERSION, COMPILER_PACKAGE } from "./tracking-events";
@@ -64,8 +65,9 @@ async function getDistinctId(): Promise<{
6465
const email = await tryGetEmail();
6566

6667
if (email) {
68+
const hashedEmail = crypto.createHash("sha256").update(email).digest("hex");
6769
return {
68-
distinct_id: email,
70+
distinct_id: hashedEmail,
6971
distinct_id_source: "email",
7072
org_id: orgId,
7173
};

0 commit comments

Comments
 (0)