0%

Learn how to secure your ASP.NET Core web app through robust and secure code

Key Features

  • Discover the different types of security weaknesses in ASP.NET Core web applications and learn how to fix them
  • Understand what code makes an ASP.NET Core web app unsafe
  • Build your secure coding knowledge by following straightforward recipes

Book Description

ASP.NET Core developers are often presented with security test results showing the vulnerabilities found in their web apps. While the report may provide some high-level fix suggestions, it does not specify the exact steps that you need to take to resolve or fix weaknesses discovered by these tests.

In ASP.NET Secure Coding Cookbook, you'll start by learning the fundamental concepts of secure coding and then gradually progress to identifying common web app vulnerabilities in code. As you progress, you'll cover recipes for fixing security misconfigurations in ASP.NET Core web apps. The book further demonstrates how you can resolve different types of Cross-Site Scripting. A dedicated section also takes you through fixing miscellaneous vulnerabilities that are no longer in the OWASP Top 10 list. This book features a recipe-style format, with each recipe containing sample unsecure code that presents the problem and corresponding solutions to eliminate the security bug. You'll be able to follow along with each step of the exercise and use the accompanying sample ASP.NET Core solution to practice writing secure code.

By the end of this book, you'll be able to identify unsecure code causing different security flaws in ASP.NET Core web apps and you'll have gained hands-on experience in removing vulnerabilities and security defects from your code.

What you will learn

  • Understand techniques for squashing an ASP.NET Core web app security bug
  • Discover different types of injection attacks and understand how you can prevent this vulnerability from being exploited
  • Fix security issues in code relating to broken authentication and authorization
  • Eliminate the risks of sensitive data exposure by getting up to speed with numerous protection techniques
  • Prevent security misconfiguration by enabling ASP.NET Core web application security features
  • Explore other ASP.NET web application vulnerabilities and secure coding best practices

Who this book is for

This ASP.NET Core book is for intermediate-level ASP.NET Core web developers and software engineers who use the framework to develop web applications and are looking to focus on their security using coding best practices. The book is also for application security engineers, analysts, and specialists who want to know more about securing ASP.NET Core using code and understand how to resolve issues identified by the security tests they perform daily.

Table of Contents

  1. ASP.NET Core 5 Secure Coding Cookbook
  2. Foreword
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Sections
    8. Getting ready
    9. How to do it…
    10. How it works…
    11. There's more…
    12. See also
    13. Get in touch
    14. Share Your Thoughts
  7. Chapter 1: Secure Coding Fundamentals
    1. Technical requirements
    2. Input validation
    3. Enabling whitelist validation using validation attributes
    4. Getting ready
    5. How to do it…
    6. How it works…
    7. Whitelist validation using the FluentValidation library
    8. Getting ready
    9. How to do it…
    10. How it works…
    11. There's more…
    12. See also…
    13. Syntactic and semantic validation
    14. Creating a custom validation attribute to implement semantic validation
    15. Getting ready
    16. How to do it…
    17. How it works…
    18. Input sanitization
    19. Getting ready
    20. How to do it…
    21. How it works…
    22. Input sanitization using the HTMLSanitizer library
    23. Getting ready
    24. How to do it…
    25. How it works…
    26. Output encoding
    27. Output encoding using HtmlEncoder
    28. Getting ready
    29. How to do it…
    30. How it works…
    31. Output encoding using UrlEncoder
    32. Getting ready
    33. How to do it…
    34. How it works…
    35. Output encoding using JavascriptEncoder
    36. Getting ready
    37. How to do it…
    38. How it works…
    39. Protecting sensitive data using the Data Protection API
    40. Getting ready
    41. How to do it…
    42. How it works…
    43. See also
  8. Chapter 2: Injection Flaws
    1. Technical requirements
    2. What is SQL injection?
    3. Fixing SQL injection with Entity Framework
    4. Getting ready
    5. How to do it…
    6. How it works…
    7. There's more…
    8. Fixing SQL injection in ADO.NET
    9. Getting ready
    10. How to do it…
    11. How it works…
    12. There's more…
    13. Fixing NoSQL injection
    14. Getting ready
    15. How to do it…
    16. How it works…
    17. There's more…
    18. Fixing command injection
    19. Getting ready
    20. How to do it…
    21. How it works…
    22. There's more…
    23. Fixing LDAP injection
    24. Getting ready
    25. How to do it…
    26. How it works…
    27. Fixing XPath injection
    28. Getting ready
    29. How to do it…
    30. How it works…
    31. There's more…
  9. Chapter 3: Broken Authentication
    1. Technical requirements
    2. Fixing the incorrect restrictions of excessive authentication attempts
    3. Getting ready
    4. How to do it…
    5. How it works…
    6. There's more…
    7. Fixing insufficiently protected credentials
    8. Getting ready
    9. How to do it…
    10. How it works…
    11. Fixing user enumeration
    12. Getting ready
    13. How to do it…
    14. How it works…
    15. Fixing weak password requirements
    16. Getting ready
    17. How to do it…
    18. How it works…
    19. Fixing insufficient session expiration
    20. Getting ready
    21. How to do it…
    22. How it works…
  10. Chapter 4: Sensitive Data Exposure
    1. Technical requirements
    2. Fixing insufficient protection of data in transit
    3. Getting ready
    4. How to do it…
    5. How it works…
    6. Fix missing HSTS headers
    7. Getting ready
    8. How to do it…
    9. How it works…
    10. There's more…
    11. Fixing weak protocols
    12. Getting ready
    13. How to do it…
    14. How it works…
    15. Fixing hardcoded cryptographic keys
    16. Getting ready
    17. How to do it…
    18. How it works…
    19. There's more…
    20. Disabling caching for critical web pages
    21. Getting ready
    22. How to do it…
    23. How it works…
  11. Chapter 5: XML External Entities
    1. Technical requirements
    2. Enabling XML validation
    3. Getting ready
    4. How to do it…
    5. How it works…
    6. There's more…
    7. Fixing XXE injection with XmlDocument
    8. Getting ready
    9. How to do it…
    10. How it works…
    11. There's more…
    12. Fixing XXE injection with XmlTextReader
    13. Getting ready
    14. How to do it…
    15. How it works…
    16. Fixing XXE injection with LINQ to XML
    17. Getting ready
    18. How to do it…
    19. How it works…
  12. Chapter 6: Broken Access Control
    1. Technical requirements
    2. Fixing IDOR
    3. Getting ready
    4. How to do it…
    5. How it works…
    6. Fixing improper authorization
    7. Testing improper authorization
    8. Getting ready
    9. How to do it…
    10. How it works…
    11. Fixing missing access control
    12. Getting ready
    13. How to do it…
    14. How it works…
    15. Fixing open redirect vulnerabilities
    16. Getting ready
    17. How to do it…
    18. How it works…
  13. Chapter 7: Security Misconfiguration
    1. Technical requirements
    2. Disabling debugging features in non-development environments
    3. Getting ready
    4. How to do it…
    5. How it works…
    6. Fixing disabled security features
    7. Getting ready
    8. How to do it…
    9. How it works…
    10. Disabling unnecessary features
    11. Getting ready
    12. How to do it…
    13. How it works…
    14. Fixing information exposure through an error message
    15. Getting ready
    16. How to do it…
    17. How it works
    18. Fixing information exposure through insecure cookies
    19. Getting ready
    20. How to do it…
    21. How it works
  14. Chapter 8: Cross-Site Scripting
    1. Technical requirements
    2. Fixing reflected XSS
    3. Getting ready
    4. How to do it…
    5. How it works…
    6. Fixing stored/persistent XSS
    7. Getting ready
    8. How it works…
    9. There's more…
    10. Fixing DOM XSS
    11. Getting ready
    12. How to do it…
    13. How it works…
  15. Chapter 9: Insecure Deserialization
    1. Technical requirements
    2. Fixing unsafe deserialization
    3. Getting ready
    4. Testing unsafe deserialization
    5. How to do it…
    6. How it works…
    7. There's more…
    8. Fixing the use of insecure deserializers
    9. Getting ready
    10. How to do it…
    11. How it works…
    12. There's more…
    13. Fixing untrusted data deserialization
    14. Testing untrusted data deserialization
    15. Getting ready
    16. How to do it…
    17. How it works…
  16. Chapter 10: Using Components with Known Vulnerabilities
    1. Technical requirements
    2. Fixing the use of a vulnerable third-party JavaScript library
    3. Getting ready
    4. Testing outdated and vulnerable third-party libraries
    5. How to do it…
    6. How it works…
    7. There's more…
    8. See also
    9. Fixing the use of a vulnerable NuGet package
    10. Getting ready
    11. Testing vulnerable NuGet packages
    12. How to do it…
    13. How it works…
    14. Fixing the use of a library hosted from an untrusted source
    15. Getting ready
    16. How to do it…
    17. How it works…
    18. There's more…
  17. Chapter 11: Insufficient Logging and Monitoring
    1. Technical requirements
    2. Fixing insufficient logging of exceptions
    3. Getting ready
    4. How to do it…
    5. How it works…
    6. Fixing insufficient logging of DB transactions
    7. How to do it…
    8. How it works…
    9. Fixing excessive information logging
    10. How to do it…
    11. How it works…
    12. Fixing a lack of security monitoring
    13. How to do it…
    14. How it works…
    15. There's more…
  18. Chapter 12: Miscellaneous Vulnerabilities
    1. Technical requirements
    2. Fixing the disabled anti-Cross-Site Request Forgery protection
    3. Getting ready
    4. How to do it…
    5. How it works…
    6. There's more…
    7. Preventing Server-Side Request Forgery
    8. Getting ready
    9. How to do it…
    10. How it works…
    11. There's more…
    12. Preventing log injection
    13. Getting ready
    14. How to do it…
    15. How it works…
    16. There's more…
    17. Preventing HTTP response splitting
    18. Getting ready
    19. How to do it…
    20. How it works…
    21. There's more…
    22. Preventing clickjacking
    23. Getting ready
    24. Clickjacking proof of concept (PoC)
    25. How to do it…
    26. How it works…
    27. Fixing insufficient randomness
    28. Getting ready
    29. How to do it…
    30. How it works…
  19. Chapter 13: Best Practices
    1. Technical requirements
    2. Getting ready
    3. Proper exception handling
    4. Getting ready
    5. How to do it…
    6. How it works…
    7. There's more…
    8. Using security-related cookie attributes
    9. Getting ready
    10. How to do it…
    11. How it works…
    12. Using a Content Security Policy
    13. Getting ready
    14. How to do it…
    15. How it works…
    16. There's more…
    17. Fixing leftover debug code
    18. Getting ready
    19. How to do it…
    20. How it works…
    21. There's more…
    22. Why subscribe?
  20. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
3.139.97.157