Input sanitization
Another complementing strategy that a developer can implement in processing input is to remove or replace unwanted characters from the data. Your application might expect some free-form text or HTML formatted input, and to avoid attacks that will take advantage of this vector, you must perform sanitization.
You can write your own methods for sanitizing and, similar to input validation, implement either a whitelisting or blacklisting approach for modifying input.
In this recipe, you will learn how to write your own code for sanitizing input.
Getting ready
Using Visual Studio Code, open the sample Online Banking app folder at \Chapter01\input-sanitization\before\OnlineBankingApp
.
How to do it…
Let's take a look at the steps for this recipe:
- Launch Visual Studio Code and open the starting exercise folder by typing the following command:
code .
- Open the
Models/FundTransfer.cs
file and add a reference to theSystem.Text.RegularExpressions...