Book Image

Mastering Web Application Development with Express

By : Alexandru Vladutu
Book Image

Mastering Web Application Development with Express

By: Alexandru Vladutu

Overview of this book

Table of Contents (18 chapters)
Mastering Web Application Development with Express
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Cross-site scripting


A Cross-site scripting (XSS) type of attack allows hackers to inject malicious client-side scripts into web applications. Once the script is injected into a trusted website, it has access to the user's sensitive information such as cookies, the content of the page, and others.

To guard our Express applications against this type of attack, we should employ the following techniques:

  • Validate data sent by the user (input)

  • Sanitize output stored on the backend, such as into a database

  • Enable content-security policy

Validating input

We should always try to validate data sent by the users before processing it. In some situations, we can validate it against a list of known values, but this isn't always the case.

A handy module to do validation is express-validator (https://www.npmjs.org/package/express-validator), which has all sorts of functions built in.

Sanitizing output

Validation is the first line of defense, but it's not enough. We cannot stop the user from entering quotes, for...