-
Notifications
You must be signed in to change notification settings - Fork 213
fix: Only match prefixes in sensitive name regex #2643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 No Changeset FoundThis PR doesn't include a changeset. A changeset (and the release label) is required to release a new version. How to add a changesetRun this command and follow the prompts: pnpm changesetRemember: Never use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, no comments
| // it's possible for el.name or el.id to be a DOM element if el is a form with a child input[name="name"] | ||
| const sensitiveNameRegex = | ||
| /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i | ||
| /^(cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn)/i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i understand the change here but
can you ask Claude to write parameterised tests proving the change and behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made a change - tbh I'm not totally convinced by this set of sensitive patterns anyway - there's lots of things that aren't sensitive that might start with exp.
Also there's part of me that thinks we shouldn't have the check here anyway:
posthog-js/packages/browser/src/autocapture.ts
Lines 41 to 44 in f7d6b69
| const shouldCaptureEl = shouldCaptureElement(elem) | |
| if (!shouldCaptureEl) { | |
| return {} | |
| } |
if a user has added the attributes to an element (even if it's a potentially sensitive element), then surely we should capture the attributes regardless?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is way more preferable to miss something safe than to capture something sensitive!
what we should do is let someone override this so that if they disagree then they can set their own and we add a property to say "hey, this is your regex, it's not on us"
(that's how we do it in replay payload capture"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having got into this a bit more, the way things are at the moment (as I understand it), we detect an element is sensitive with shouldCaptureElement, but that check doesn't apply in all places, so the elements would be captured regardless in elements_chain. I think it maybe needs some wider thought than this one small fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 106 in 19fc73b
| if (isSensitiveElement(elem) && ['name', 'id', 'class', 'aria-label'].indexOf(attr.name) === -1) return |
I believe this is the check we do for capturing the elements_chain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to close this PR for now - working on something over on #2647 instead
|
Size Change: +24 B (0%) Total Size: 5.08 MB
ℹ️ View Unchanged
|
| expect(shouldCaptureElement(input)).toBe(false) | ||
| }) | ||
|
|
||
| it.each(['document-expiry', 'success_message', 'account-settings', 'compass-icon'])( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document-expiry and compass-icon would have failed before because of exp and pass appearing anywhere in the string.
success_message and account-setting would have passed because cc wasn't at the start.
It looks like this has been in the SDK forever, but the regex pattern we use was matching any substring for most of our sensitive looking fields (everything except
cc). I think the intent would've been to only look at prefixes, as we were doing forcc.Currently if, for example,
expappeared anywhere inside thename/idattribute of an element then we wouldn't capture it.https://posthoghelp.zendesk.com/agent/tickets/42648
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file