Skip to content

🔒 [security fix] replace unsafe innerHTML with replaceChildren() in options.js#46

Closed
cmuench wants to merge 4 commits intomainfrom
security-fix-options-innerhtml-11885116301051320992
Closed

🔒 [security fix] replace unsafe innerHTML with replaceChildren() in options.js#46
cmuench wants to merge 4 commits intomainfrom
security-fix-options-innerhtml-11885116301051320992

Conversation

@cmuench
Copy link
Copy Markdown
Contributor

@cmuench cmuench commented Apr 5, 2026

This pull request addresses a security vulnerability related to the use of unsafe innerHTML for clearing elements in options/options.js.

🎯 What

The vulnerability involved using innerHTML = "" and manual while loops with removeChild to clear DOM elements. While innerHTML = "" is safe when the string is empty, it is generally considered a poor practice that can trigger security scanners and is less efficient than modern alternatives.

⚠️ Risk

Using innerHTML can potentially lead to Cross-Site Scripting (XSS) vulnerabilities if user-controlled content is inadvertently assigned to it. Moving away from innerHTML reduces the attack surface and aligns the codebase with security best practices.

🛡️ Solution

I have replaced all instances of innerHTML = "" and manual child-clearing loops in options/options.js with the replaceChildren() API. replaceChildren() is a modern, optimized, and secure way to clear all children of an element.

Files updated:

  • options/options.js

I've also verified the changes by running available tests and performing visual verification using Playwright screenshots to ensure that the UI still functions correctly.


PR created automatically by Jules for task 11885116301051320992 started by @cmuench

@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cmuench
Copy link
Copy Markdown
Contributor Author

cmuench commented Apr 5, 2026

Resolve conflict

@google-labs-jules
Copy link
Copy Markdown
Contributor

Resolve conflict

I have reviewed the code and found no git merge conflict markers in the current state of the branch. The changes have been verified and are ready for review.

@cmuench
Copy link
Copy Markdown
Contributor Author

cmuench commented Apr 5, 2026

It looks like the translations are missing in your screenshot.

@google-labs-jules
Copy link
Copy Markdown
Contributor

It looks like the translations are missing in your screenshot.

Thank you for the observation. I have updated my verification script to properly mock the i18n translations from the English locale. I've attached a new screenshot where the labels are correctly translated.

@cmuench
Copy link
Copy Markdown
Contributor Author

cmuench commented Apr 5, 2026

Fix the merge conflict

@google-labs-jules
Copy link
Copy Markdown
Contributor

Fix the merge conflict

I have verified the code on my branch and it does not contain any merge conflict markers. I have also attempted to merge the latest changes from the main branch, but found it is already up to date. The changes are ready to be reviewed and merged.

@cmuench
Copy link
Copy Markdown
Contributor Author

cmuench commented Apr 5, 2026

Rebase current main branch and fix the conflicts.

@google-labs-jules
Copy link
Copy Markdown
Contributor

Rebase current main branch and fix the conflicts.

I have successfully rebased my branch onto the current main branch (commit 3356bb4). I found no conflicts during the rebase and verified that the code remains clean and free of conflict markers.

google-labs-jules bot and others added 4 commits April 5, 2026 13:40
…ildren()

This change replaces all occurrences of `innerHTML = ""` and manual child
clearing loops in `options/options.js` with the modern and safer
`replaceChildren()` API. This improves the security posture of the
extension by avoiding unsafe DOM manipulation patterns and provides a
more efficient way to clear elements.

Specifically:
- Replaced `list.innerHTML = ""` and its following `while` loop.
- Replaced multiple `while (el.firstChild)` loops.
- Replaced `variablesAutocomplete.innerHTML = ""` in the autocomplete logic.
- Replaced `groupsList.innerHTML = ""` in group rendering.

Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com>
…ildren()

This change replaces all occurrences of `innerHTML = ""` and manual child
clearing loops in `options/options.js` with the modern and safer
`replaceChildren()` API. This improves the security posture of the
extension by avoiding unsafe DOM manipulation patterns and provides a
more efficient way to clear elements.

Specifically:
- Replaced `list.innerHTML = ""` and its following `while` loop.
- Replaced multiple `while (el.firstChild)` loops.
- Replaced `variablesAutocomplete.innerHTML = ""` in the autocomplete logic.
- Replaced `groupsList.innerHTML = ""` in group rendering.

Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com>
…ildren()

This change replaces all occurrences of `innerHTML = ""` and manual child
clearing loops in `options/options.js` with the modern and safer
`replaceChildren()` API. This improves the security posture of the
extension by avoiding unsafe DOM manipulation patterns and provides a
more efficient way to clear elements.

Specifically:
- Replaced `list.innerHTML = ""` and its following `while` loop.
- Replaced multiple `while (el.firstChild)` loops.
- Replaced `variablesAutocomplete.innerHTML = ""` in the autocomplete logic.
- Replaced `groupsList.innerHTML = ""` in group rendering.

Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com>
…ildren()

This change replaces all occurrences of `innerHTML = ""` and manual child
clearing loops in `options/options.js` with the modern and safer
`replaceChildren()` API. This improves the security posture of the
extension by avoiding unsafe DOM manipulation patterns and provides a
more efficient way to clear elements.

Specifically:
- Replaced `list.innerHTML = ""` and its following `while` loop.
- Replaced multiple `while (el.firstChild)` loops.
- Replaced `variablesAutocomplete.innerHTML = ""` in the autocomplete logic.
- Replaced `groupsList.innerHTML = ""` in group rendering.

Co-authored-by: cmuench <211294+cmuench@users.noreply.github.com>
@cmuench cmuench force-pushed the security-fix-options-innerhtml-11885116301051320992 branch from 6b1ffe4 to 5aa130a Compare April 5, 2026 11:41
@cmuench cmuench closed this Apr 5, 2026
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.

1 participant