How to disable the execution of JavaScript, when it is output to the page when it is contained in the data

We use jquery-datatable to render a piece of material obtained by table, and one of the columns will encounter something like:

8080::HTTP/1.1 200 OK | < script > window.location.href = " http://example:8080/a.asp";</script>

when rendering, the browser executes the script and the page jumps.
what can I do to prevent running JavaScript, to solve security implications?

Mar.13,2021

Common security issues, the technical term XSS , you can search for related articles.

The simple solution here is to escape & < > and other special characters by html escape.

& -> &
< -> <
> -> >

how to disable execution when outputting to a page

try to escape a string or fail direct validation when enters . A data is added only once, but you don't know how many times to visit it.


");
    s = s.replace(/ /g, "");
    s = s.replace(/\'/g, "'");
    s = s.replace(/\"/g, """);
    s = s.replace(/\n/g, "<br>");
    return s;
}
xssText('<script>window.location.href = "http://example:8080/a.asp";</script>')
Menu