Is Web App Security Training Worth Your Time?
Some of the key takeaways we brought back from a web app security training.
You can find countless statistics on cyber security. The ones I come across most frequently agree that the security market keeps growing, that security engineers are in high demand, and that their pay is going up. On top of that, securityheaders.com reports that roughly 46% of the websites it scanned received an F grade for their security-related HTTP headers. So when I recently had the opportunity to join a web app security training, I took it. Here are some of the things I learned and my thoughts on them.
Playing the hacker
In the first part of the training, we got to step into the shoes of hackers. We chose a domain and began with DNS reconnaissance, a technique for gathering information about:
- the DNS records of the target domain,
- associated IP addresses,
- subdomains,
- mail servers.
With this information, we can examine the network infrastructure and search for possible vulnerabilities. We frequently came across subdomains of test servers. I’ve seen projects in which test environments ran on a copy of the production database, and such environments typically lack production-grade observability, developer attention, and security. Plenty of tools support this kind of reconnaissance – dnsrecon, for instance. Once you, as a hacker, pick a server, you scan it to quickly spot common vulnerabilities, misconfigurations, or outdated software. Many tools exist for this too, nikto among them. It is a basic server scanner, but a decent place to start. We also took a deep dive into the zaproxy scanner, a far more powerful tool that pentesters use widely.
Armed with these tools, we received a set of test applications in which we had to find vulnerabilities and exploit them. We found a way to carry out a Cross Site Scripting (XSS) attack on the site by injecting a JS script into one of the application’s URLs. Picture a real-world app with a flaw like that – paired with social engineering, such malicious links could be sent to the app’s users as shortened URLs, and someone would very likely click them. We also discovered a way to inject SQL into the application’s database.
For me at least, learning web app security through this kind of hands-on practice is worth far more than simply reading about it. Some projects let you do exactly that, such as natas, where at every level you have to hack the server by finding a vulnerability that gives you the credentials for the next one. There are 33 levels, and I can say that from level 7 onward it gets quite tough (for a beginner like me).
Playing the developer
The second part of the training centered on the developer’s point of view, which was what interested me most. How should software security be addressed during design? What good practices and security knowledge bases are out there?
The design process
When building new web services, technical discussions tend to revolve around databases and frameworks. These matter, of course, but security frequently gets neglected along the way. So how do we “design” for it? We were introduced to a step-by-step method called threat modeling, which boils down to these questions:
- What are we building?
- What could go wrong (in terms of security)?
- What can we do about it?
- Is that enough?
With these questions, the design discussion can loop over questions 3 and 4 until we reach the answer “yes, that’s enough”, or until we can no longer find a way to challenge the solution. We should also design with the attacker’s profile in mind. Hacker groups, for instance, are highly technical, but there are also former employees, opportunists, and even ordinary users.
Suppose we’re designing a login feature for our website. What threat do ordinary users pose – what could go wrong? People tend to pick simple, reused passwords, which brute force methods can crack. What can we do about it? Enforce a password policy. Is that enough? Most likely yes. Let’s take it further and assume user credentials have leaked. What can we do? We can require 2FA to block unauthorized access. Once more, is that enough? That probably depends on what kind of product you’re building, but I hope the idea is clear.
Now let’s consider threats from opportunists. These are people after personal gain; they’ll try to cheat to get something for themselves, without necessarily aiming to harm your business. What could go wrong? An opportunist might try to log in to an existing user’s account to reach certain resources. What can we do about it? We can watch for suspicious activity using signals such as User-Agent header values, the location a request comes from, or the number of attempts, and we can notify users about such activity.
And what about actual hackers? They could intercept traffic to our site and try to read user credentials. We can encrypt the connection with TLS. Is that enough? Not quite – users might still reach the site over an insecure HTTP connection, followed by a server redirect, which leaves us exposed to man-in-the-middle attacks. So again, what can we do? We can add the HTTP Strict Transport Security (HSTS) header to our server responses. It instructs browsers to always use HTTPS for our domain (for a certain period), which reduces the risk.
During the training we worked through similar examples, and every attacker profile brings many considerations. Naturally, it’s important to stay reasonable and design against the threats that are likely. Services that are part of critical infrastructure, such as banks and online government services, need a different security level than a static web page. Still, a lot of security can be gained through simple measures such as using security-related HTTP headers correctly.
Good practices
Let’s go over some good practices from a developer’s perspective. When several teams build different services, enforcing and maintaining standards gets harder, and this is where reference architectures can help. They might be as basic as a microservice template with correct security-related server settings, or more elaborate architectures made up of several components. Kept current with the latest practices and standards, they can take some of the load off developers.
Another idea worth bringing up is reducing the attack surface, which means keeping the number of possible entry points for attackers as small as possible. The most basic example is deleting unused endpoints from our API. In a cloud environment, it might mean limiting access to management interfaces such as SSH, or placing services like databases in private subnets without direct internet access.
For developers, OWASP is likely among the best knowledge bases available. Its website offers plenty of resources, but a good first step is its set of HTTP header recommendations, the “Secure Headers Project”. In my view, headers are the low-hanging fruit when it comes to improving app security. Another valuable source is MITRE, with its cybersecurity defences & attacks strategies, each action described in detail.
There are good practices for everyday development, too. One is to watch out for the default configurations of the components you use, since defaults are often suitable only for local development. MongoDB, for example, shipped with authentication turned off by default in its first few major versions. Attackers took advantage of this misconfiguration by going after publicly exposed MongoDB instances, stealing their data, and demanding ransom to restore it.
Another easy way to boost security is to validate and sanitize data in our APIs. Your frontend forms may perform validation, but treat that purely as UX, since it can be bypassed easily. Everything that reaches your API should be considered potentially dangerous. Validation and sanitization protect you from attacks such as SQL injection. Also consider what your API returns when errors occur (including unexpected ones). Web scanners will try to break your API with malformed input or with load, and error messages can reveal to attackers which libraries and databases you use or where injection might be possible. Error handling is key here, and the more generic your API errors and response codes, the better. Your clients and the business may not like hearing this, so you may need to find a balance.
Summary
Everyone agrees security matters, but we don’t all have to become security experts. Experts have produced guidelines we can follow, and together with some good practices, they will likely earn our services a solid security grade. The training lasted 2 days, and I’ve shared only a small part of what I found especially interesting. It was run by a cybersecurity company. Thanks for reading!