How to Defend a Web Application with Engineering
We got our CTO, Tom Lindley , to drop us his top tips for building a secure web app. Read on to find out his views on using engineering to shore up your defences.
I’ve been doing lots of interviews recently and one question consistently gets pretty poor or incomplete responses. That question is “How do you build a web application that is secure?”
You get lots of standard responses like; Web Application Firewalls, Static Code Analysis, CSRF Tokens, Input Validation. Yes, all of that stuff is good, but it’s not really what I meant.
Developers are lazy, forgetful, time restricted, under pressure and constantly interrupted, all while trying to maintain a huge mental model of a complex ecosystem in their heads as they build stuff (speaking very much from experience).
The question then is “how do you stop humans making mistakes?”. Well, you can’t, but you can engineer to reduce that scope for error to a minimum. As of 2021 Broken Access Control is now the top item on the OWASP Top 10. Insecure Design has also been added at number 4.
I have been massively influenced by the aviation industry over the last 5 years or so; the safety culture, redundancy and incredible effort put into investigations when things do go wrong. So, I thought I’d write out a concrete example of how we try to use some of these sentiments to reduce developer mistakes by using defence in depth and standardisation.
Standardise & Defence In Depth
The OnSecurity portal application has five standard defences on ingress; these are designed in a standardised format that cannot be easily bypassed (i.e., unless you really try). This design makes it much harder to make something insecure rather than the other way around.
1. Authentication
Firstly, we have authentication middleware that runs on all endpoints defined within a file:
领英推荐
2. Security Policies Per API Endpoint
Security policies are applied to all authenticated endpoints. To prevent mistakes we follow these rules:
3. Client Segregation
All models containing client information have an interface on them that runs a standardised query to validate the user has access to the client.
This makes it almost impossible to return information for a client you do not have access to and we have client filtering built into standardised API query ecosystem (mentioned below).
4. Permissions Within Standardised API Queries
5. Controller Level Permissions
This is where we apply additional checks which are mostly business logic rather than grassroots permissions. This level is the most error prone but you can be fairly sure if you get down to this level then everything that should’ve been checked already has been checked.
Summary
This is all obviously very high-level but I'd love to hear from you if you'd like more clarification on any of the above, if you think we've missed anything, or if you think I'm just talking out of my arse.
Co-Founder & CTO @ OnSecurity
2 年I tried to focus on the human aspects of building secure web applications. Something I think is largely uncovered by all of the clickbait "top 10 tips" articles out there. Technology is great but it's still operated by humans. Humans are horribly unpredictable machines.