XSS attack prevention/mitigation
While cross-site scripting attacks can be dangerous and difficult to detect, there are ways to prevent and mitigate them. The basic principles of input handling are validation, sanitization and escaping.
The validation process ensures that the user input is legitimate and properly formatted according to a fixed set of validation rules. The theory here is to treat all data or inputs as untrusted until they are met with certain criteria such as type and length requirements. For example, The Phone Number input field can contain only numbers and cannot be submitted when a user is trying to type letters or special symbols to this field.
Sanitizing user input is another mitigation method that essentially requires all user data to be cleaned of potentially dangerous symbols that are usually used in HTML markup and JavaScript code. When the HTML tags are allowed as a part of user input, “white lists” of tags are used and all tags that are not allowed end up removed.
Keep in mind that some user input that doesn’t contain any malicious scripts can still be a source of errors in the application database. Data might become corrupted in the process of saving it due to how databases handle some special symbols. For this reason, during input sanitation, you also need to perform encoding of database-sensitive content. This process is required not only for preventing attacks but for overall application stability.
Escaping mechanism ensures that all data displayed to the user can’t be interpreted as HTML or JavaScript code. Escaping user input often means preventing the use of certain characters. It reduces the possibilities for attackers.
The «<» and «>»characters are often removed from use to prevent a possibility to display HTML code from other user input. For example, if an attacker put some harmful code inside his or her username on a social network, the escaping process will not allow the code to be executed after you see an attacker’s profile.
Web Application Firewalls (WAF) are a widely used application firewall that is effective in reducing and preventing XSS attacks. These firewalls apply a set of rules to HTTP conversations that help to protect servers, web applications, and ultimately, the users. These firewalls come in a variety of forms, and they may need to be customized according to the needs of a user or an organization.
Comments
Post a Comment