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

refactor: [M3-7990] - Replace sanitize-html with DOM friendly alternative #10378

Merged
merged 6 commits into from
Apr 22, 2024

Conversation

abailly-akamai
Copy link
Contributor

@abailly-akamai abailly-akamai commented Apr 16, 2024

Description πŸ“

This PR replaces sanitize-html with the DOM friendly, well supported dompurify package.

https://github.com/cure53/DOMPurify

sanitize-html is meant to run with NodeJS - aka on the server. This substitution standardizes our codebase and avoid potential issues running nodeJS modules (path, FS, url, source-map-js) in the browser while improving the developer experience as we're removing a large amount of warnings in the console.

Screenshot 2024-04-16 at 15 20 33

This PR is meant as a 1/1 replacement, meaning all tests should be passing and current sanitization in CM should be unaltered.

The bundled compressed size difference between both packages is negligible.

ℹ️ Note: As a rule of thumb, sanitizing in the browser is only for the presentation layer. We don't want to get in the habit of sanitizing data we're sending to the API.

Changes πŸ”„

List any change relevant to the reviewer.

  • Replace sanitize-html with dompurify.
  • Adapt API to match functionality

Preview πŸ“·

No visual change

How to test πŸ§ͺ

Prerequisites

  • run yarn && yarn up with current branch

Verification steps

In order to check some of the areas where we sanitize HTML, use the content matches in the table below. It sahould give you a pretty good idea what area to check. Namely, events (notification dropdown & event page), tickets,

sanitizeHTML util HighlightedMarkdown Component
Screenshot 2024-04-16 at 15 39 04 Screenshot 2024-04-16 at 15 39 52

As an Author I have considered πŸ€”

Check all that apply

  • πŸ‘€ Doing a self review
  • ❔ Our contribution guidelines
  • 🀏 Splitting feature into small PRs
  • βž• Adding a changeset
  • πŸ§ͺ Providing/Improving test coverage
  • πŸ” Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • πŸ‘£ Providing comprehensive reproduction steps
  • πŸ“‘ Providing or updating our documentation
  • πŸ•› Scheduling a pair reviewing session
  • πŸ“± Providing mobile support
  • β™Ώ Providing accessibility support

@abailly-akamai abailly-akamai self-assigned this Apr 16, 2024
@abailly-akamai abailly-akamai changed the title tech-stories: [M3-7990] - Replace sanitize-html with DOM friendly alternative refactor: [M3-7990] - Replace sanitize-html with DOM friendly alternative Apr 16, 2024
@abailly-akamai abailly-akamai marked this pull request as ready for review April 16, 2024 19:52
@abailly-akamai abailly-akamai requested a review from a team as a code owner April 16, 2024 19:52
@abailly-akamai abailly-akamai requested review from dwiley-akamai and jaalah-akamai and removed request for a team April 16, 2024 19:52
'title',
'align',
'class',
'rel',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We allow them, but then we strip them all unless it is for <span class="version" />

This will be all cleaned up once we get rid of out eventMessageGenerator transformers, which is part of this epic

},
sanitizingTier: 'strict',
text: localError || '',
}).toString();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need to satisfy the types here with toString()

would love to confirm those changes are good with people familiar with this particular Firewall files. Maybe @carrillo-erik ?

KEEP_CONTENT: disallowedTagsMode === 'discard' ? false : true,
RETURN_DOM: false,
RETURN_DOM_FRAGMENT: false,
RETURN_TRUSTED_TYPE: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

node.removeAttribute('class');
}
}
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

legacy handlers which I hope to get rid of soon once we refactor event generators

Copy link

Coverage Report: βœ…
Base Coverage: 81.8%
Current Coverage: 81.8%

Copy link
Contributor

@bnussman-akamai bnussman-akamai left a comment

Choose a reason for hiding this comment

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

Very nice. Feels good to finally get this taken care of. Thanks for taking it on!

Copy link
Contributor

@jaalah-akamai jaalah-akamai left a comment

Choose a reason for hiding this comment

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

Confirmed I see no more sea of yellow! πŸ‘

@jaalah-akamai jaalah-akamai added the Approved Multiple approvals and ready to merge! label Apr 19, 2024
@abailly-akamai abailly-akamai merged commit 5672faf into linode:develop Apr 22, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Multiple approvals and ready to merge! Tech Debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants