When a page puts user input into HTML without escaping it, the input can be markup. A search term like <script>...</script> runs in the next visitor's browser. OWASP files this under Injection (A05:2025); the weakness is CWE-79.
The fix is output encoding: escape the text for the place it goes. In HTML that means turning <, >, &, quotes into their entities, so the browser shows them as characters instead of running them. env.escapeHtml(text) does this. Escape at the moment you build the HTML, around every piece of untrusted input, and keep the visible text the same for an ordinary query. Removing the word "script" is not a fix: there are many other tags and attributes.
Escape each piece of untrusted input where it enters the HTML.