• Labs icon Lab
  • Security
Google Cloud Platform icon
Labs

Sanitize User Input for C# Applications

In this lab, you will practice securing web applications against SQL Injection, XSS, and CSRF attacks. When you finish, you will have a fully functional ASP.NET Core MVC application with implemented protections for each vulnerability.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 1h 15m
Published
Clock icon Apr 29, 2025

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Getting Started in the Lab Environment

    Here are the initial instructions and explanation of the lab environment. Read this while your environment is busy creating itself from nothing. Yes, this violates physics; we know. How fun!

  2. Challenge

    Sanitize User Input for C#: Concept Review

    You'll review core web vulnerabilities: SQL Injection, XSS, and CSRF. Learn how untrusted input, unencoded output, and missing request validation expose risks—and how to mitigate them in ASP.NET Core MVC apps.

  3. Challenge

    SQL Injection Vulnerability and Mitigation

    You'll analyze a C# console app with a SQL injection vulnerability caused by string concatenation. You'll then refactor it using parameterized queries with SqlCommand and test it with both valid and malicious inputs to confirm the fix.

  4. Challenge

    Cross-Site Scripting (XSS) Vulnerability and Prevention

    You'll build a Razor view in ASP.NET Core MVC that initially renders unencoded input, exposing an XSS risk. You'll then apply WebUtility.HtmlEncode and test with script payloads to confirm the secure version renders the input as harmless text.

  5. Challenge

    Cross-Site Request Forgery (CSRF) Prevention

    You'll create an ASP.NET Core MVC app with a state-changing form that lacks CSRF protection. You'll then add anti-forgery tokens and apply the ValidateAntiForgeryToken attribute to secure it and ensure POST requests come from trusted sources.

  6. Challenge

    Knowledge Check for Sanitize User Input for C# Applications

    In this challenge, you will answer some assessment questions that will test your understanding of the concepts you learned throughout this lab.

Sean Wilkins is an accomplished networking consultant and writer for infoDispersion (www.infodispersion.com) who has been in the IT field for over 20 years working with several large enterprises.

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.