Page
1
Pro API Security Testing in ASP.NET Core Detect and Prevent Vulnerabilities Using C# and WebApplicationFactory — Roman Canlas
Page
2
Pro API Security Testing in ASP.NET Core Detect and Prevent Vulnerabilities Using C# and WebApplicationFactory Roman Canlas
Page
3
Pro API Security Testing in ASP.NET Core: Detect and Prevent Vulnerabilities Using C# and WebApplicationFactory ISBN-13 (pbk): 979-8-8688-2390-9 ISBN-13 (electronic): 979-8-8688-2391-6 https://doi.org/10.1007/979-8-8688-2391-6 Copyright © 2026 by Roman Canlas This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Ryan Byrnes Desk Editor: Laura Berendson Editorial Project Manager: Gryffin Winkler Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a Delaware LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https://www.apress.com/gp/services/ source-code. If disposing of this product, please recycle the paper Roman Canlas Seattle, WA, USA
Page
4
To my younger self: a frequenter of Book Sale, a bargain heaven bookstore, endlessly searching through secondhand and dog-eared Apress books for hidden gems, never knowing he would one day become an Apress author himself.
Page
5
(This page has no text content)
Page
6
(This page has no text content)
Page
7
(This page has no text content)
Page
8
(This page has no text content)
Page
9
(This page has no text content)
Page
10
(This page has no text content)
Page
11
(This page has no text content)
Page
12
xiii About the Author Roman Canlas is an accomplished application security engineer who built and runs the global application security program for a Fortune 500 company. His background in C# and ASP.NET development gives him a developer's eye for identifying code-level vulnerabilities and conducting web security testing. He holds GIAC GWAPT, ISC2 CSSLP, and EC-Council CASE.NET certifications, along with a master's in Information Systems and a bachelor's in Computer Science. He wrote this book to share practical approaches that developers and security teams can actually implement. This book distils his experience into security tests you can write and run today.
Page
13
xv About the Technical Reviewer Vijay Pahuja is a senior lead software engineer with 25+ years of experience in enterprise architecture, cloud-native systems, and secure API platforms. He specializes in building resilient, compliant, high-scale digital services in regulated environments. Vijay is an IEEE Senior Member and serves as a Technical Program Committee member and peer reviewer for international IEEE-related conferences. He also regularly contributes technical writing to industry publications on modern software engineering practices.
Page
14
xvii Acknowledgments I would like to express my heartfelt gratitude to the Apress and Springer teams. Special thanks to Ryan Byrnes, acquisitions editor, for believing in this book and giving me the opportunity to share my knowledge. I also thank Shobana Srinivasan, Gryffin Winkler, and the rest of the production team for their dedication and hard work, as well as Vijay Pahuja for his outstanding technical review. I would also like to acknowledge Tobias Ahnoff and Martin Altenstedt, whose presentation on Test-Driven Application Security at the NDC Security 2023 conference inspired the concept for this book. I am grateful to stand on the shoulders of these giants.
Page
15
xix Introduction APIs have become the backbone of modern software development. From mobile applications to microservices architectures, from cloud-native solutions to IoT ecosystems, APIs serve as the connective tissue that enables digital transformation. This ubiquity, however, comes with significant risk. The same interfaces that power your applications and connect your services also present attractive targets for attackers. Every endpoint you expose, every data exchange you enable, and every integration you build creates a potential attack surface that determined adversaries will probe and exploit. This book equips you with the knowledge and practical techniques to defend your ASP.NET Core APIs against the most critical security threats. You will learn to write security tests that catch vulnerabilities before they reach production, integrate security validation into your development workflow, and build APIs that are not just functional but comprehensively secure. The approach we take treats security not as a burden or an afterthought but as a fundamental quality attribute of well-crafted software. Why This Book The statistics paint a sobering picture of API security today. According to industry research, the vast majority of organizations have experienced API security incidents, and API attacks continue to grow as the preferred pathway for data breaches. Yet despite this reality, many development teams lack practical guidance on how to test for and prevent API vulnerabilities within their existing workflows. Traditional security testing often occurs at the end of the development cycle, performed by specialized security teams using tools unfamiliar to developers. This approach creates friction, delays releases, and frequently results in security issues being discovered too late to address properly. The developers who build APIs rarely have the opportunity to learn security testing techniques that integrate naturally with their existing skills and tools. This book bridges that gap. Using WebApplicationFactory, a class intrinsic to the .NET framework and already familiar to ASP.NET Core developers, you will learn to write security tests that fit seamlessly into your existing test suites. You will work with C# code
Page
16
xx you can understand, modify, and extend. You will test against a realistic banking API that demonstrates real-world vulnerabilities and their remediation. Most importantly, you will develop a security mindset that enables you to identify and proactively address vulnerabilities throughout the development process. What You Will Learn This book provides comprehensive coverage of API security testing, organized around the OWASP API Security Top 10 which is the industry-standard framework identifying the most critical risks facing APIs today. Each vulnerability category receives focused attention, with practical testing techniques you can implement immediately. 1. Broken Object Level Authorization: You will learn to test that your APIs properly verify resource ownership, ensuring users can only access data they are entitled to see. 2. Broken Authentication: You will verify that authentication mechanisms cannot be bypassed, that tokens are properly validated, and that session management is secure. 3. Broken Object Property Level Authorization: You will test that sensitive data fields are properly protected and that users cannot manipulate properties they should not access. 4. Unrestricted Resource Consumption: You will implement tests for rate limiting and resource protection that prevent denial-of- service attacks. 5. Broken Function Level Authorization: You will verify that administrative and privileged functions are properly protected from unauthorized access. 6. Unrestricted Access to Sensitive Business Flows: You will learn techniques to detect and prevent automated abuse of your business logic. 7. Server-Side Request Forgery: You will test that user-supplied URLs and endpoints cannot be exploited to access internal resources. InTroduCTIon
Page
17
xxi 8. Security Misconfiguration: You will verify that security headers, CORS policies, and framework configurations are properly implemented. 9. Improper Inventory Management: You will learn to test for exposed debug endpoints, outdated API versions, and undocumented functionality. 10. Unsafe Consumption of APIs: You will implement tests that verify proper validation of data received from third-party services. Beyond individual vulnerability categories, you will learn how to integrate security testing into your CI/CD pipelines, automate vulnerability detection, and establish practices that make security testing a natural part of your development workflow rather than an occasional checkpoint. Who This Book Is For This book is designed for ASP.NET Core developers who want to take ownership of their API security. Whether you are building new APIs or securing existing ones, the testing techniques presented here will strengthen your security posture. QA engineers will find practical approaches for incorporating security validation into their testing strategies. DevOps professionals and application security engineers will learn how to embed security testing into CI/CD pipelines for continuous security validation. We assume familiarity with C# and basic ASP.NET Core development concepts. You should be comfortable writing code, creating test projects, and working with HTTP- based APIs. However, no prior security expertise is required. This book is specifically designed to build your security knowledge from the ground up, providing the context and explanation needed to understand both the vulnerabilities and their remediation. The content is intentionally version-agnostic. The testing patterns and security principles presented here apply across ASP.NET Core versions, ensuring the knowledge you gain remains valuable as the framework evolves. You will learn approaches that transcend specific version features, focusing on enduring security concepts that protect your APIs regardless of which .NET version you target. InTroduCTIon
Page
18
xxii How This Book Is Organized This book follows a logical progression from the OWASP API Security Top 10 risks with each item going through practical vulnerability testing. Foundation Chapters 1 and 2 establish the groundwork for everything that follows. You will explore the relationship between security and quality, understanding why security deserves treatment as a core quality attribute rather than an optional enhancement. You will learn about WebApplicationFactory and how to leverage this powerful tool for security testing. You will set up your development environment and explore the companion banking API that serves as our testing laboratory throughout the book. The OWASP API Security Top 10 Chapters 3 through 12 form the core of the book, with each chapter dedicated to one of the OWASP API Security Top 10 vulnerabilities. Each chapter follows a consistent pattern: you will understand what the vulnerability is and why it matters, examine vulnerable code to see how the flaw manifests, write tests that detect the vulnerability, implement secure code that addresses the issue, and verify your fix with comprehensive testing. This hands-on approach ensures you not only understand the theory but can apply the techniques immediately in your own projects. Integration and Beyond Chapters 13 and 14 take your security testing practice to the next level. You will learn how to integrate your security tests into CI/CD pipelines, automate vulnerability detection across your entire API surface, and establish continuous security validation that catches issues before they reach production. The final chapter provides resources for continuing your security journey, including certifications, training programs, and community resources that will support your ongoing development as a security- conscious developer. InTroduCTIon
Page
19
xxiii About the Companion Code All the code examples in this book are available in a companion GitHub repository. The repository contains a banking API application with both vulnerable and secure implementations organized to mirror the OWASP API Security Top 10 categories. Each vulnerability chapter has corresponding Before and After folders, allowing you to examine vulnerable code, run the security tests against it, study the secure implementation, and verify the fix. This structure provides an invaluable learning tool. You can experiment with the vulnerable implementations to understand how security flaws manifest in production code, then study the secure implementations to learn proper defensive patterns. The tests themselves serve as executable documentation of security requirements, demonstrating exactly what behaviors should and should not be allowed. The source code for this book is available on GitHub via the book's product page, located at https://github.com/Apress/Pro-API-Security-Testing-in-ASP.NET-Core. Getting Started The most effective way to use this book is to code along with each chapter. Set up your development environment as described in Chapter 2, clone the companion repository, and run the tests as you encounter them. The hands-on experience of seeing tests fail against vulnerable code and pass against secure code builds intuition that reading alone cannot provide. Take time to experiment. Modify the vulnerable code to create variations, and see if your tests still catch them. Extend the test suites to cover edge cases specific to your domain. The patterns presented in each chapter are starting points that are templates you can adapt and expand based on your specific requirements. Security is a practice, not a destination. The techniques in this book provide a strong foundation, but the threat landscape continues to evolve. Approach each chapter not just as material to learn but as skills to develop through practice and application. In Chapter 1, we begin our journey by exploring the fundamental relationship between security and quality. You will learn why treating security as a quality attribute transforms how you approach API development, and you will be introduced to WebApplicationFactory as your primary tool for security testing. Let's get started. InTroduCTIon
Page
20
1 © Roman Canlas 2026 R. Canlas, Pro API Security Testing in ASP.NET Core, https://doi.org/10.1007/979-8-8688-2391-6_1 CHAPTER 1 Introduction to API Security Security is quality, and quality is security. This isn’t just a catchy phrase. It’s a profound view that they aren’t separate concerns but the same basic attribute viewed through different lenses. In modern software development, especially for APIs, we’ve traditionally treated security and quality as distinct disciplines with other teams, tools, and various processes. But at their core, both represent the same goal: building software that functions correctly under all circumstances, including when someone’s actively trying to break it. Ensuring these APIs are secure is no longer just a security concern. It’s a fundamental quality issue. An API that works perfectly but contains security vulnerabilities isn’t just “insecure”. It’s a low-quality product. Why Security Is Actually a Quality Attribute The ISO/IEC 25010 standard for software quality includes security as one of the eight main quality characteristics, and it’s right alongside those traditional attributes. This standard shows that the relationship between security and quality isn’t arbitrary but intrinsic. Security isn’t an optional enhancement but a fundamental component of quality. Here’s how security directly impacts other quality dimensions: • Reliability: A security breach can take your API down just as effectively as a coding bug. Many major service outages that appear to be reliability issues can be attributed to the result of security incidents.