You are right that the concept of "safe" is nebulous, but the goal here is specifically to be XSS-safe [1]. Elements or properties that could allow scripts to execute are removed. This functionality lives in the user agent and prevents adding unsafe elements to the DOM itself, so it should be easier to get correct than a string-to-string sanitizer. The logic of "is the element currently being added to the DOM a <script>" is fundamentally easier to get right than "does this HTML string include a script tag".[1] https://developer.mozilla.org/en-US/docs/Web/API/Element/set...
entuno|5 days ago
intrasight|5 days ago
Dylan16807|5 days ago
But for html snippets you can pretty much just check that tags follow a couple simple rules between <> and that they're closed or not closed correctly.