How to remove malicious HTML (XXS, etc.) from content materials?

I have a content presentation form that contains several input fields, all of which are sent directly to the database when sending. When this content is requested, it is printed.

I realized that this is a security issue.

How can I crop only malicious HTML (XSS) while retaining formatting tags ( b, ietc.)?

+3
source share
6 answers

@pst ... . , , , HTML Tidy ( Source Forge), , DOMDocument:: loadHTML .

HTML Tidy , . . (. BLOB , - , -).

.

+1

htmlspecialchars , (, &lt;b&gt; <b>).

+1

mysql_stripslashes(), htmlspecialchars() urldecode(), , , int typecast.

0

, "" html- - , <strong> <em>. , , , .

0

, ...

PHP , :

htmlspecialchars
0

.

, : , javascript, - , javascript ,

  • , html

-, , . , <, > & &lt;, &gt; &amp; .

, , , textarea

  • , html, .

, , , db.

, , , , , ,

Separate the characters <and >before exiting or storing - this is not a good solution, in my opinion, since this is an unnecessary change to user input, but some people prefer it.

0
source

Source: https://habr.com/ru/post/1787094/


All Articles