Skip to content

How to combat XSS

Alexis edited this page Apr 17, 2020 · 2 revisions

Ways to protect your website against XSS

Now that you've read on how and why XSS attacks can be extremely dangerous and easy to execute, you're probably wondering how can you protect yourself against it ?

1. Sanitize your Input

Sanitizing your input, means that whenever you type something on your website, it is not directly interpreted as text, it will first go trough a filter, and if that filter detects malicious intents such as JavaScript or html tags, it won't let them go trough. use a sanitizer for your preferred language, such as SanitizeHelper for Ruby on rails or Html Sanitizer for .NET

2. Train and Raise Awareness

when you are developing your web app, everyone in the dev team must be aware of all the dangers associated with XSS. Train your staff, and raise awareness about XSS attacks to every single one of the team members, even if they are not developers, it could still help

3. Set an HTTPonly Flag

By setting an HTTPonly flag, the cookies of your web app will not be accessible via client-side JavaScript that means that hacker won't be able to steal the cookie of your website and use them for malicious purposes

4. don't trust any user input

Treat all the user input as untrusted, any html input is vulnerable to an XSS attack, treat your authenticated users' input the same way as anybody else's input

5. Regularly scan your app using Acunetix

Your developer could introduce a new feature onto your webapp that contains an XSS attack vulnerability, be sure to regularly scan your app with Acunetix for possible XSS breaches and vulnerabilities. XSS attacks could cost you alot, and even more on your reputation, if your webb application can't be trusted, nobody will use it and you will lose customers !

An example of my own

To sanitize my input in my rails app, I added this sanitizer for my devise pages.

def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:full_name, :email, :password, :password_confirmation])
  end
end

Clone this wiki locally