XSS attack in wordpress?

600 Views Asked by At

I am developing a WordPress theme. for the security of it with XSS. here i have two queries:

  1. How to detect theme can be infected with XSS attack? or already infected?

  2. How to prevent it to be infected with XSS?

i know this is related to WordPress and i should post this on WordPress. i did already here but no solution yet.

1

There are 1 best solutions below

0
On

XSS isn't an infection, it's a type of security vulnerability. You can learn more about preventing XSS vulnerabilities here.

  1. How to detect theme can be infected with XSS attack? or already infected?

There isn't an easy answer to this question. To determine if a theme is vulnerable to XSS attacks, you need to audit every source file and check every place that output is generated to make sure it's not doing anything dangerous (e.g. <form action="<?php echo $_SERVER['PHP_SELF']; ?>">).

  1. How to prevent it to be infected with XSS?
  1. Always escape output to prevent user-provided data from adding HTML entities, such as <, >, etc. A quick helper method to use here is:

    function noHTML($input, $encoding='UTF-8')
    {
        return htmlspecialchars($input, ENT_QUOTES | ENT_HTML5, $encoding);
    }
    

    Note that this will prevent users from supplying any HTML at all.

  2. Use a library such as HTML Purifier to escape entire blocks of HTML to prevent XSS attacks.