Repository navigation
Fixed three bugs in IdentifyUpdate (prevent PII leak) - #44
Merged
Merged
Conversation
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
marked this pull request as draft
November 20, 2026 03:52
… 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
marked this pull request as ready for review
November 20, 2026 04:40
1 of 2 tasks
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>
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
left a comment
Collaborator
There was a problem hiding this comment.
@imnasnainaec reviewed 3 files and all commit messages, and resolved 3 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on tombogle).
Collaborator
Contributor
Author
tombogle
enabled auto-merge (squash)
November 20, 2026 15:04
imnasnainaec
approved these changes
Nov 20, 2026
imnasnainaec
left a comment
Collaborator
There was a problem hiding this comment.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on tombogle).
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>
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changed
IdentifyUpdateso 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:
CreateSanitized()silently droppedUILanguageCode. The sanitized copy it returns only carried overFirstName/LastName/Email/OtherProperties-UILanguageCodewas never included, so withretainPii: false(the default) it was always empty from the momentAnalyticswas 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 likeOtherPropertiesalready was.IdentifyUpdate(null)threwNullReferenceException. Either immediately (inCreateSanitized, ifretainPiiwas false) or on the nextIdentifycall onces_userInfoitself becamenull(ifretainPiiwas true). This library needs to be failsafe for any caller input, so a nulluserInfois now just a no-op.As a related safeguard for the main fix:
ApplyPiiPolicynow takes an optionalpreviousUserInfo. If a name is unchanged frompreviousandprevious's value already matches the shapeCreateSanitizedproduces (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.
This change is