Use innerHTML only if needed and on escaped input - #791
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request improves frontend security by replacing innerHTML with innerText throughout the codebase and introducing HTML escaping via a new escapeHtml utility function. The changes aim to prevent potential XSS vulnerabilities when handling user input or dynamic content.
- Introduces
escapeHtmlfunction and applies it to user-generated content (file names, search inputs) - Replaces most
innerHTMLassignments withinnerTextto prevent HTML interpretation - Refactors
validation.tsby extracting lookup tables and optimizing replace operations
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| validation.ts | Adds escapeHtml function; extracts and refactors slug/diacritics maps; optimizes string replacement logic |
| updates.ts | Replaces innerHTML with innerText for version names and status messages |
| pages.ts | Adds HTML escaping for search input; updates search handler to use innerText and escapeHtml |
| backups.ts | Replaces innerHTML with innerText for backup metadata display |
| upload-input.ts | Applies escapeHtml to file names before inserting into DOM |
| tags-input.ts | Replaces innerHTML with innerText for tag labels and list clearing |
| range-input.ts | Changes output value display from innerHTML to innerText |
| duration-input.ts | Updates label text setting from innerHTML to innerText |
| date-input.ts | Changes calendar time display from innerHTML to innerText |
| color-input.ts | Updates color value label from innerHTML to innerText |
| fileslist.ts | Adds HTML escaping for search; applies escapeHtml to file names in search results |
馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request focuses on improving frontend security and consistency by standardizing how text content is inserted into the DOM and by enhancing input sanitization. The main changes include replacing most uses of
innerHTMLwithinnerTextto prevent possible XSS vulnerabilities, introducing and applying a newescapeHtmlutility function, and refactoring thevalidation.tsfile for better maintainability and correctness.Security and sanitization improvements:
Introduced a new
escapeHtmlfunction invalidation.tsto safely escape user-provided or dynamic text before inserting it into the DOM, and updated various components (e.g., files list, pages view, upload input) to use this function when handling user input or file names. [1] [2] [3] [4] [5] [6] [7] [8]Replaced most uses of
innerHTMLwithinnerTextthroughout UI components (such as file lists, color/range/duration/tags inputs, backups, and updates views) to prevent interpreting potentially unsafe HTML. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]Refactoring and maintainability:
validation.tsby extracting and reorganizing utility functions and lookup tables for escaping, diacritics, and slug creation, making the code more modular and easier to maintain. [1] [2]Input handling improvements:
Consistency improvements:
innerTextfor labels, dropdowns, and tags, and consistently escaping text where necessary. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]These changes collectively improve the security and reliability of the codebase, especially regarding user input and DOM updates.