Skip to content

Commit

Permalink
fix: change .innerHTML to .textContent for CSP compliance
Browse files Browse the repository at this point in the history
I think we should use `textContent` to reduce CSP (Content  Security Policy) requirements. If we add CSP `require-trusted-types-for 'script'`, then it blocks `innerHTML` unless it's `TrustedHTML`, however in the case of this lib's usage, we can simply replace the `innerHTML` with `textContent` which has the exact same effect and is more CSP compliant

For reference, you can see this [PR](vitejs/vite#10801) on the Vite project, they've done the exact same code change.
  • Loading branch information
ghiscoding committed Nov 7, 2023
1 parent 46f42b0 commit cff0b6d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion autocomplete.ts
Expand Up @@ -319,7 +319,7 @@ export default function autocomplete<T extends AutocompleteItem>(settings: Autoc
*/
function update() {

container.innerHTML = '';
container.textContent = '';
input.setAttribute('aria-activedescendant', '');

// function for rendering autocomplete suggestions
Expand Down

0 comments on commit cff0b6d

Please sign in to comment.