-
Notifications
You must be signed in to change notification settings - Fork 392
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
base: main
Are you sure you want to change the base?
Changes from all commits
a32ae52
f66e0c9
1dc18c5
1690e40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
helix-importer-ui | ||
helix-importer-ui | ||
scripts/purify.min.js |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -537,7 +537,7 @@ function buildBlock(blockName, content) { | |
vals.forEach((val) => { | ||
if (val) { | ||
if (typeof val === 'string') { | ||
colEl.innerHTML += val; | ||
colEl.textContent += val; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the |
||
} else { | ||
colEl.appendChild(val); | ||
} | ||
|
@@ -564,6 +564,7 @@ async function loadBlock(block) { | |
const decorationComplete = new Promise((resolve) => { | ||
(async () => { | ||
try { | ||
// eslint-disable-next-line no-unsanitized/method | ||
const mod = await import( | ||
`${window.hlx.codeBasePath}/blocks/${blockName}/${blockName}.js` | ||
); | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,27 @@ import { | |
sampleRUM, | ||
} from './aem.js'; | ||
|
||
/** | ||
* Minimal escaping of HTML special characters | ||
* | ||
* NOTICE: Mitigates a big class of XSS attacks, but not all of them. | ||
* Always try to refactor your code to simply avoid using unsafe browser APIs. | ||
* | ||
* example where it would not help, because the attribute has a Javascript context: | ||
* const userInput = 'alert(document.cookie)'; | ||
* container.innerHTML = `<img src="x" onerror="${escapeHtml(userInput)}"/>`; | ||
* @param {string} unsafe | ||
* @returns {string} | ||
*/ | ||
export function escapeHtml(unsafe) { | ||
return unsafe | ||
.replaceAll('&', '&') | ||
.replaceAll('<', '<') | ||
.replaceAll('>', '>') | ||
.replaceAll('"', '"') | ||
.replaceAll('\'', '''); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something for aem.js? |
||
/** | ||
* Builds hero block and prepends to main in a new section. | ||
* @param {Element} main The container element | ||
|
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.
Note that the original
fragment
block source is in the block-collection and should probably be fixed there first, then updated here.