Skip to content

Add Masking for PostHog Session Recording#480

Open
Derek Siemens (DerekSiemens) wants to merge 1 commit intomasterfrom
posthog
Open

Add Masking for PostHog Session Recording#480
Derek Siemens (DerekSiemens) wants to merge 1 commit intomasterfrom
posthog

Conversation

@DerekSiemens
Copy link
Contributor

Description of the change

Adds masking for sensitive fields and data points so that they do not make it into Posthog.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation or Development tools (readme, specs, tests, code formatting)

Links

  • Jira issue number: (PUT IT HERE)
  • Process.st launch checklist: (PUT IT HERE)

Checklists

Development

  • Prettier was run (if applicable)
  • The behaviour changes in the pull request are covered by specs
  • All tests related to the changed code pass in development

Paperwork

  • This pull request has a descriptive title and information useful to a reviewer
  • This pull request has a Jira number
  • This pull request has a Process.st launch checklist

Code review

  • Changes have been reviewed by at least one other engineer
  • Security impacts of this change have been considered

Copilot AI review requested due to automatic review settings February 26, 2026 22:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a reusable masking utility and applies it across Mint’s tax-and-cash/registration UI so sensitive user/banking/tax fields can be excluded from PostHog session recordings (via DOM annotations).

Changes:

  • Added posthogMasking utility helpers to flag sensitive fields and generate masking attributes.
  • Applied masking attributes broadly across tax/user/banking forms and payout details displays.
  • Added heuristic masking for generic input fields based on field type/name patterns.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/mint-components/src/utils/posthogMasking.ts Introduces helper functions to detect sensitive fields and generate a data-sqm-sensitive attribute map.
packages/mint-components/src/components/tax-and-cash/sqm-user-info-form/sqm-user-info-form-view.tsx Applies masking attrs to user info form and its inputs/selects/checkbox.
packages/mint-components/src/components/tax-and-cash/sqm-user-info-form/small-views/IndirectTaxDetailsView.tsx Applies masking attrs to indirect tax details inputs/selects/checkboxes and container form.
packages/mint-components/src/components/tax-and-cash/sqm-payout-details-card/sqm-payout-details-card-view.tsx Masks payout detail text (PayPal email / account preview).
packages/mint-components/src/components/tax-and-cash/sqm-indirect-tax-form/sqm-indirect-tax-form-view.tsx Masks indirect tax form container and radio controls.
packages/mint-components/src/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form.tsx Adds masking attrs to verification dialog/code component and several banking inputs/selects.
packages/mint-components/src/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form-view.tsx Masks banking form container and radio controls.
packages/mint-components/src/components/tax-and-cash/sqm-banking-info-form/formDefinitions.tsx Applies masking attrs across generated banking form fields.
packages/mint-components/src/components/sqm-name-fields/sqm-name-fields-view.tsx Masks first/last name inputs.
packages/mint-components/src/components/sqm-input-field/sqm-input-field-view.tsx Adds heuristic masking based on field type/name and applies it to the generic input.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

? useDemoBankingInfoForm(this)
: useBankingInfoForm(this);

const sensitiveAttrs = sensitiveMaskAttrs(true);
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

The sensitiveAttrs declaration is mis-indented relative to surrounding code, which looks like a formatting slip and makes the render method harder to scan. Please align it with the other const declarations (or run the formatter used in this package).

Suggested change
const sensitiveAttrs = sensitiveMaskAttrs(true);
const sensitiveAttrs = sensitiveMaskAttrs(true);

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +39
export function sensitiveMaskAttrs(enabled: boolean): Record<string, string> {
return enabled
? {
"data-sqm-sensitive": "true",
}
: {};
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

sensitiveMaskAttrs adds a custom data-sqm-sensitive attribute, but there are no references in this repository that configure PostHog/rrweb to mask elements matching this attribute. As-is, this change only annotates DOM nodes and may not actually prevent session recording from capturing the data. Consider using an attribute that rrweb/PostHog masks by default, or add/configure the PostHog initialization to treat [data-sqm-sensitive] as a mask selector (and document that dependency).

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +40
const SENSITIVE_FIELD_PATTERNS = [
"name",
"address",
"city",
"state",
"province",
"region",
"postal",
"zip",
"phone",
"tax",
"account",
"iban",
"swift",
"routing",
"beneficiary",
"paypal",
"bank",
"card",
"payment",
];

export function shouldMaskSensitiveField(field?: string): boolean {
if (!field) {
return false;
}

const normalized = field.toLowerCase();
return SENSITIVE_FIELD_PATTERNS.some((pattern) =>
normalized.includes(pattern)
);
}

export function sensitiveMaskAttrs(enabled: boolean): Record<string, string> {
return enabled
? {
"data-sqm-sensitive": "true",
}
: {};
}
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

New masking logic (shouldMaskSensitiveField, sensitiveMaskAttrs) is untested. Since this package already has unit tests for utils (e.g., src/utils/utils.spec.ts), add specs to cover representative field names (case-insensitivity, empty/undefined input, and ensuring non-sensitive names return false).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants