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

feat: Configure Mozilla's Eslint Plugin eslint-plugin-no-unsanitized + DOMPurify.sanitize + escapeHtml #416

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

andreituicu
Copy link

@andreituicu andreituicu commented Oct 16, 2024

@fkakatie
Copy link
Member

results of aem-psi-check would be necessary here.

@andreituicu
Copy link
Author

andreituicu commented Oct 16, 2024

@fkakatie completely agree. It looks like there's a problem with my fork, because when I access https://xss-lint-dompurify--helix-project-boilerplate--andreituicu.aem.live the head doesn't have any scripts/css... Could I possibly get write permissions to the boilerplate? That way I can create the branches directly in the project and recreate the PRs including PSI values.

@@ -22,7 +22,8 @@ export async function loadFragment(path) {
const resp = await fetch(`${path}.plain.html`);
if (resp.ok) {
const main = document.createElement('main');
main.innerHTML = await resp.text();

main.innerHTML = DOMPurify.sanitize(await resp.text());
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that the original fragment block source is in the block-collection and should probably be fixed there first, then updated here.

head.html Outdated Show resolved Hide resolved
@@ -537,7 +537,7 @@ function buildBlock(blockName, content) {
vals.forEach((val) => {
if (val) {
if (typeof val === 'string') {
colEl.innerHTML += val;
colEl.textContent += val;
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that the aem.js source is here and the build result gets copied to the boilerplate.

.replaceAll('"', '"')
.replaceAll('\'', ''');
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something for aem.js?

@andreituicu
Copy link
Author

@rofe I agree with your suggestions of moving different changes into aem-lib and aem-block-collection.
I created this PR mostly as a consolidated view to collect feedback and discuss whether this is a direction we'd like to go in, or not.

I'm not 100% convinced it is simple enough for developers (which I might be wrong) when they should escape, when they should sanitize and when are both needed.

Using any of them will make the linter happy, but depending on context they aren't both secure, or said differently, each offers protection in specific cases.

I'm not sure if it would be a better approach to just keeping it simple by saying that any use of unsafe API is unsafe.
The problem then becomes creating big structures with just document.createElement, document.appendChild and document.setAttribute and fragments always need to disable the linter rules, like: https://github.com/adobe/aem-boilerplate/pull/415/files#diff-7fdbc35e8d9d1b49261e0470a1900621a5eb2508a2818a9ee18e2e60514fae4eR26

Copy link

aem-code-sync bot commented Oct 22, 2024

Page Scores Audits Google
📱 / PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ / PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

@andreituicu
Copy link
Author

Interesting results 1.6 LCP, that's really at the edge. I got 0.9 LCP on pagespeed: https://pagespeed.web.dev/analysis/https-xss-lint-dompurify--helix-project-boilerplate--andreituicu-aem-live/f2hqca9aqv?form_factor=mobile

@andreituicu
Copy link
Author

andreituicu commented Oct 22, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants