Skip to content

Fixed three bugs in IdentifyUpdate (prevent PII leak) - #44

Merged
tombogle merged 5 commits into
masterfrom
fix-identify-update-leaks-pii
Nov 20, 2026
Merged

tombogle merged 5 commits into
masterfrom
fix-identify-update-leaks-pii

Conversation

@tombogle

@tombogle tombogle commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Changed IdentifyUpdate so that it uses the retainPii value passed into the constructor to apply the same policy. This ensures that a caller can't accidentally leak PII just by calling IdentifyUpdate with an object that still has it.

Background: IdentifyUpdate(UserInfo) previously stored whatever UserInfo it was given verbatim, with no sanitization, even when the Analytics object was constructed with retainPii: false. That meant a consumer calling IdentifyUpdate with its own unsanitized UserInfo later in the session (e.g. to push an unrelated profile update) would silently undo the PII protection the constructor set up, overwriting the sanitized profile with real email/name data.

While fixing this, found and fixed two other bugs along the way:

  1. CreateSanitized() silently dropped UILanguageCode. The sanitized copy it returns only carried over FirstName/LastName/Email/OtherProperties - UILanguageCode was never included, so with retainPii: false (the default) it was always empty from the moment Analytics was first constructed, regardless of anything a caller passed in later. Confirmed via Mixpanel: PII-protected profiles had an empty string for that property. Fixed - it isn't PII, so it's now copied through like OtherProperties already was.

  2. IdentifyUpdate(null) threw NullReferenceException. Either immediately (in CreateSanitized, if retainPii was false) or on the next Identify call once s_userInfo itself became null (if retainPii was true). This library needs to be failsafe for any caller input, so a null userInfo is now just a no-op.

As a related safeguard for the main fix: ApplyPiiPolicy now takes an optional previous UserInfo. If a name is unchanged from previous and previous's value already matches the shape CreateSanitized produces (a regex: original first character, optional -, 1-10 digits - the string form of a signed 32-bit hash code), that field is carried over as-is instead of being hashed again. Unlike email sanitization (already idempotent, since re-stripping an already-domain-only address is a no-op), hashing an already-hashed name produces a different value every time, so without this, a caller that re-sanitizes a previously-sanitized name on every call would keep scrambling it further instead of leaving it stable.

Test suite: 31 tests total (several new ones added for the fixes above), all passing.


Devin Review


This change is Reviewable

IdentifyUpdate(UserInfo) previously stored whatever UserInfo it was
given verbatim, with no sanitization, even when the Analytics object
was constructed with retainPii: false. That meant a consumer calling
IdentifyUpdate with its own unsanitized UserInfo later in the session
(e.g. to push an unrelated profile update) would silently undo the
PII protection the constructor set up, overwriting the sanitized
profile with real email/name data.

Remember retainPii from construction and apply the exact same policy
(via the new shared, testable Analytics.ApplyPiiPolicy helper) in
IdentifyUpdate, so a caller can't accidentally leak PII just by
calling IdentifyUpdate with an object that still has it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tombogle tombogle self-assigned this Nov 20, 2026
@tombogle tombogle added the bug label Nov 20, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

Comment thread src/DesktopAnalytics/Analytics.cs Resolved
@tombogle
tombogle marked this pull request as draft November 20, 2026 03:52
tombogle and others added 3 commits November 19, 2026 22:55
… names

CreateSanitized() silently dropped UILanguageCode (it isn't PII - no
reason to strip it, same as OtherProperties). With retainPii:false
(the default), this meant UILanguageCode was empty from the moment
Analytics was first constructed, so IdentifyUpdate's fix in the
previous commit was sending an empty UI-language trait no matter what
a caller passed in. Confirmed via Mixpanel: PII-protected profiles had
an empty string for that property.

Separately, ApplyPiiPolicy now takes an optional `previous` UserInfo.
If a name is unchanged from previous and previous's value already
looks like CreateSanitized's hash shape (a regex: original first
character, optional '-', 1-10 digits - matching a signed 32-bit hash
code's string form), that field is carried over as-is instead of being
hashed again. Unlike email sanitization (already idempotent, since
re-stripping an already-domain-only address is a no-op), hashing an
already-hashed name produces a new, different value every time -
needed so a caller that fetches Analytics's own current UserInfo,
tweaks one unrelated field, and calls IdentifyUpdate doesn't scramble
the name further on every single call.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
IdentifyUpdate(null) previously threw NullReferenceException (either
immediately in CreateSanitized, or on the next Identify call once
s_userInfo itself became null). This library needs to be failsafe for
any caller input, so null is now just a no-op.

Also made LooksAlreadyHashed internal (instead of private) so tests
can assert directly on it - ApplyPiiPolicy_NameChangedFromPrevious_
HashesTheNewNameInstead previously only checked that the sanitized
name differed from the previous one and started with the expected
first letter; it didn't actually confirm the result looks hashed
rather than just being the raw incoming name with a coincidentally
matching first letter. Added explicit assertions for that, plus a
dedicated parameterized test for LooksAlreadyHashed covering the
int.GetHashCode() string-shape boundaries (Int32.MinValue/MaxValue,
11-digit rejection, multi-character prefix rejection, empty/null).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The previous test only asserted DoesNotThrow, which happened to pass
for a reason unrelated to the guard actually working: with no real
Analytics singleton constructed in this test run, any code path that
got past the null check would NRE on s_singleton regardless of
userInfo, so the assertion alone couldn't distinguish "guarded
correctly" from "coincidentally still throws before anything observable
happens, for an unrelated reason." Added an internal CurrentUserInfo
accessor (test-only) and assert it's unchanged after the call.

Verified by temporarily removing the guard and confirming the
strengthened test fails (NullReferenceException in ApplyPiiPolicy),
then restoring it and confirming all 31 tests pass again.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tombogle
tombogle marked this pull request as ready for review November 20, 2026 04:40
@tombogle tombogle changed the title Make IdentifyUpdate honor the retainPii policy set at construction Fixed three bugs in IdentifyUpdate (prevent PII leak) Nov 20, 2026
tombogle added a commit to sillsdev/Glyssen that referenced this pull request Nov 20, 2026
The actual code fix (UpdateUiLanguageForUser / Analytics.IdentifyUpdate)
depends on a SIL.DesktopAnalytics release that isn't published yet -
see sillsdev/DesktopAnalytics.net#44. Nothing
else in this branch is ready to land until that's released; this PR
stays in draft until then.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
imnasnainaec

This comment was marked as resolved.

Shortens the XML doc comments on ApplyPiiPolicy and IdentifyUpdate per
review feedback, moves the PII-safety guarantee into IdentifyUpdate's
summary so it shows in IntelliSense tooltips, and simplifies the null
no-op test to rely on NUnit's natural failure-on-exception instead of
an explicit DoesNotThrow wrapped in explanatory comments.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@imnasnainaec imnasnainaec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imnasnainaec reviewed 3 files and all commit messages, and resolved 3 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on tombogle).

@imnasnainaec

imnasnainaec commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

:lgtm: but I don't have permission in this repo to approve.

@tombogle

tombogle commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

:lgtm: but I don't have permission in this repo to approve.

I gave you write access now, but apparently the approval is not retroactive.

@tombogle
tombogle enabled auto-merge (squash) November 20, 2026 15:04

@imnasnainaec imnasnainaec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on tombogle).

@tombogle
tombogle merged commit b7821f5 into master Nov 20, 2026
3 checks passed
@tombogle
tombogle deleted the fix-identify-update-leaks-pii branch November 20, 2026 15:11
tombogle added a commit to sillsdev/Glyssen that referenced this pull request Nov 20, 2026
Analytics.IdentifyUpdate now honors retainPii:false correctly, per
sillsdev/DesktopAnalytics.net#44 (now merged
and released). UpdateUiLanguageForUser's existing call is safe as of
this version - documented why, in place.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants