Preventing log injection
In Chapter 11, Insufficient Logging and Monitoring, we learned about the importance of logging. Logging provides us with the necessary visibility to find out about a series of important events in our ASP.NET Core web application. However, hackers can also exploit logging if the user-controlled log information we create is not validated. Having malicious inputs in our log entries can also exploit the vulnerabilities of a log viewer, if one exists.
For instance, a web-based log viewer might have a cross-site script vulnerability, and viewing the log entries with an XSS payload, along with the data, can exploit this weakness. In this recipe, we will prevent the log injection vulnerability in our code by implementing input sanitization.
Getting ready
Run the sample app to verify that there are no build or compile errors. In your command shell, navigate to the sample app folder at \Chapter12\log-injection\before\OnlineBankingApp
and run the following command...