Skip to content
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

fix: sanitize class string more #925

Merged
merged 4 commits into from
Dec 7, 2023
Merged

Conversation

pauldambra
Copy link
Member

We are very intolerant of class strings that contain multiple spaces, tabs, or new lines when processing autocapture.

Technically the class attribute should always be a space separated set of strings, but computers let you generate all kinds of HTML 🙈

Follow-up to #919

This sanitizes the class string in more places so that we generate a working elements chain string even with an invalid css class.

@pauldambra pauldambra requested a review from a team December 6, 2023 23:23
@pauldambra
Copy link
Member Author

@tiina303 since this touches an area you're actively working on.

I tried to keep a minimal change so hopefully I can fix the issue in PostHog/posthog#19068 without clashing with your work

Copy link

github-actions bot commented Dec 6, 2023

Size Change: +460 B (0%)

Total Size: 745 kB

Filename Size Change
dist/array.full.js 176 kB +115 B (0%)
dist/array.js 118 kB +115 B (0%)
dist/es.js 118 kB +115 B (0%)
dist/module.js 118 kB +115 B (0%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 12 kB
dist/recorder-v2.js 104 kB
dist/recorder.js 58.4 kB
dist/surveys.js 41.5 kB

compressed-size-action

@tiina303 tiina303 requested a review from davemurphysf December 7, 2023 12:42
Copy link
Contributor

@tiina303 tiina303 left a comment

Choose a reason for hiding this comment

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

honestly I know very little of this, I was mainly just moving code around. Let's make sure we mirror in plugin-server side & maybe add comments to keep in sync

Copy link
Contributor

@davemurphysf davemurphysf left a comment

Choose a reason for hiding this comment

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

The implementation looks fine, but we should test for all the acceptable whitespace characters

it('returns elementsChain correctly with newlines in css', () => {
const elTarget = document.createElement('a')
elTarget.setAttribute('href', 'http://test.com')
elTarget.setAttribute('class', 'test-class\n test-class2 test-class3 test-class4 \r\n test-class5')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add \t and \f characters in here, just for completeness sake?

Copy link
Contributor

@davemurphysf davemurphysf left a comment

Choose a reason for hiding this comment

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

LGTM

@pauldambra pauldambra added the bump patch Bump patch version when this PR gets merged label Dec 7, 2023
@pauldambra pauldambra merged commit 7ee1b74 into master Dec 7, 2023
13 checks passed
@pauldambra pauldambra deleted the fix/more-class-sanitization branch December 7, 2023 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants