Skip to content
Home ยป Blog ยป Secure .NET Web API Endpoints by Default

Secure .NET Web API Endpoints by Default

I missed ๐™จ๐™š๐™˜๐™ช๐™ง๐™ž๐™ฃ๐™œ one endpoint โ€” ๐˜ช๐˜ฏ ๐˜ฅ๐˜ฆ๐˜ท โ€” on my .๐—ก๐—˜๐—ง ๐—ช๐—ฒ๐—ฏ ๐—”๐—ฃ๐—œ a few years back. It was a good lesson, and it led me to adopt a ‘๐˜€๐—ฒ๐—ฐ๐˜‚๐—ฟ๐—ฒ ๐—ฏ๐˜† ๐—ฑ๐—ฒ๐—ณ๐—ฎ๐˜‚๐—น๐˜’ mindset. ๐Ÿ”  

It’s easy to overlook ๐˜ฆ๐˜ฏ๐˜ฅ๐˜ฑ๐˜ฐ๐˜ช๐˜ฏ๐˜ต security; one common practice is using ๐˜ช๐˜ฏ๐˜ฉ๐˜ฆ๐˜ณ๐˜ช๐˜ต๐˜ข๐˜ฏ๐˜ค๐˜ฆ: creating a base abstract controller class with a ๐˜ฅ๐˜ฆ๐˜ง๐˜ข๐˜ถ๐˜ญ๐˜ต ๐˜ด๐˜ฆ๐˜ค๐˜ถ๐˜ณ๐˜ช๐˜ต๐˜บ ๐˜ฑ๐˜ฐ๐˜ญ๐˜ช๐˜ค๐˜บ. Sounds robust, right? But imagine a new team member creating a controller and forgetting to inherit from this base. The result? ๐—ฃ๐—ผ๐˜๐—ฒ๐—ป๐˜๐—ถ๐—ฎ๐—น๐—น๐˜† ๐˜‚๐—ป๐˜€๐—ฒ๐—ฐ๐˜‚๐—ฟ๐—ฒ๐—ฑ ๐—ฒ๐—ป๐—ฑ๐—ฝ๐—ผ๐—ถ๐—ป๐˜๐˜€.  

This is just one scenario among many. To avoid such pitfalls, you can start ๐˜€๐—ฒ๐—ฐ๐˜‚๐—ฟ๐—ถ๐—ป๐—ด ๐—”๐—Ÿ๐—Ÿ ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ฒ๐—ป๐—ฑ๐—ฝ๐—ผ๐—ถ๐—ป๐˜๐˜€. How? By invoking the ๐š๐šŽ๐šš๐šž๐š’๐š›๐šŽ๐™ฐ๐šž๐š๐š‘๐š˜๐š›๐š’๐šฃ๐šŠ๐š๐š’๐š˜๐š—() method on ๐šŠ๐š™๐š™.๐™ผ๐šŠ๐š™๐™ฒ๐š˜๐š—๐š๐š›๐š˜๐š•๐š•๐šŽ๐š›๐šœ() during startup. This ensures that every controller or endpoint ๐—ฑ๐—ฒ๐—บ๐—ฎ๐—ป๐—ฑ๐˜€ ๐—ฎ๐˜‚๐˜๐—ต๐—ฒ๐—ป๐˜๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ณ๐—ถ๐—ฟ๐˜€๐˜ โ€” ๐˜ข๐˜ต ๐˜ญ๐˜ฆ๐˜ข๐˜ด๐˜ต. ๐Ÿ” 

๐š๐šŽ๐šš๐šž๐š’๐š›๐šŽ๐™ฐ๐šž๐š๐š‘๐š˜๐š›๐š’๐šฃ๐šŠ๐š๐š’๐š˜๐š—() can be set up in different ways via a ๐™‹๐™ค๐™ก๐™ž๐™˜๐™ฎ. For instance, it can be configured to require a specific ๐™ง๐™ค๐™ก๐™š or ๐™˜๐™ก๐™–๐™ž๐™ข to increase the default security level.

PS: ๐˜๐˜ฏ๐˜ต๐˜ฆ๐˜จ๐˜ณ๐˜ข๐˜ต๐˜ช๐˜ฐ๐˜ฏ ๐˜ฐ๐˜ณ ๐˜ฏ๐˜ข๐˜ณ๐˜ณ๐˜ฐ๐˜ธ ๐˜ต๐˜ฆ๐˜ด๐˜ต๐˜ด can ensure all endpoints are properly secured.

How do you ensure your controllers and endpoints remain locked tight? ๐Ÿค”

Secure all Web API endpoints