Alright, this is our agenda for today. First, we'll be going over what WAFs are. I think many of you already know what they are. Otherwise, you probably wouldn't be here. Just so we start with an even play for everyone. Then, we'll go over what we've learned at Datadog operating a very large-scale WAF and the struggle that comes with it. We'll try to address a bit how we deal with false positives and false negatives. And then, we'll finish by sharing how we try to make them a bit better. Alright, who are we first? I'm Emmanuelle. I'm a software engineer at Datadog. I'm based in Paris. And I've worked on machine learning models for the past four years. So, not a security background at all. And actually, last year, I decided to join Datadog to work on our application security product. And this is my co-presenter, Emile. So, I'm Emile Gospier. I'm a security researcher at Datadog, also based in Paris. I've been working on a WAF and a RASP solution for the last five years. First, at Screen, then Datadog, following an acquisition in 2021. And, yeah, let's talk about WAFs. You may know about them. If you don't, that's a security tool that was created in the mid-90s, when web applications started to become more complex, more useful, and thus, a more enticing target. We didn't really have anything to do to help protect them. So, we looked at other tools, and a promising one was firewalls. They're working really great at the network level. So, the idea was, let's take them and bring them to the application layer. And instead of running on specific rules, like this IP, this port, this whatever, it was more, yeah, let's run regexes or dictionaries to find suspicious patterns in that. And if you find them in the incoming request, that's probably because it's bad. And, yeah, that's pretty much it. WAFs today are pretty much the backbone of runtime application security. And that's for a few reasons. First, they are super easy to explain. In just a few words, I was able to give you a good view of what they are. They're also incredibly easy to customize. Because they're based on regexes and dictionaries, you have an entire industry of rulesets that you can use, or you can even customize them yourself. They're also really easy to demo. All you need to do to show that your WAF works is plug it on the Internet. And just the noise from the Internet is going to create a bunch of alerts, and, hey, you have a great security tool, you're protecting everyone. And finally, it never hurts, it's actually recorded by compliance. So if you're dealing with credit cards, yeah, you need a WAF, basically. So, yeah, all of that came together to make WAF an incredibly popular product. However, WAF tends to give a bit of a false sense of security. Because what a WAF does is that it looks for suspicious requests. It's running regexes, dictionaries, that's what it does. But then it means that if you can make your malicious attack look unsuspicious, then it's going to go through. And if you happen to have a user that sends another request that happens to look suspicious, they need to be matched. And there is not really anything you can do about it. That's WAF working as design. So, yeah, a few alternatives were tried over time, like RASP, IASP, but they never really went anywhere. No solution really got anywhere as popular as WAF. We talked about what they are. Emmanuel is going to tell you about how to make one. Yeah, how do we build a WAF? Well, first, of course, you need a web application because that's what you want to protect. In front of that, most of the time, you're going to put a reverse proxy to route all the incoming traffic to your web application. All right. Now, let's build a WAF. First element that we need is a rule engine, of course. We're going to put it on the reverse proxy because it's very convenient. It's where we're going to be able to see all the incoming traffic and filter out the malicious request if we need to. Second element we need, a rule set. Here, we're mentioning the OWASP core rule set because it's a very popular one across the industry. It's open source, so you can also use it to build your own rule set on top of it. Here, you can see we mentioned PL1 for Paranoia Level 1. What it means is it's supposed to be not too noisy, so it's supposed to be a set of rules that shouldn't trigger too many alerts for us. Okay. All right. Well, good. Last element we need, the monitoring. It can be just a text file where you push all of your alerts, or it can be a super fancy dashboard that you've built. Okay. We're all set. I think we can activate the WAF. And this is more or less what happened the first time we did it. We started crying. We got a bunch of alerts. And we were like, okay, what do we do with this? And we took a step back and were like, okay, this is actually a great learning experiment. So what did we learn, Emil? So the learnings we are going to share are based on us operating a WAF at a pretty large scale. We are talking around a billion requests per second across hundreds of thousands of organizations. And the first and most important learning we took away from that is that the accuracy of a WAF rule is totally unpredictable at scale. You can think that your rule is perfect. Until it's tested, you have no idea. So they will tend to converge quite fast. So if you can test them on a broad enough set of data, within a few hours you will have a good idea of how it's going to behave. But if you only tested them on WordPress or CMS, and you deployed them on an e-commerce website, I mean, you can have a French customer going to share their address, which has a quote and OR, and then the WAF is going to freak out. I mean, of course, this is a SQL injection, no? Yeah. The other important consequence from that is that even if you do very simple modifications, like you just expand it a little bit further, like you add a couple of duplication steps, you need to test them again because you don't know what you are missing before. The other side of this coin, however, is that even if you have a crazy rule that shouldn't work, it's usually worth testing them just in case. To illustrate that, we're going to go back like to late 2021, when AppSec just caught fire, and we had log4j drop on us a few weeks before Christmas. And for those of you who don't know, it was an RCE in the log4j library, which is used by Java application to log. And if you don't know, Java applications love to log. So when it came out, the initial PLC was something like that, where if you could get log4j to log this, you had an RCE. So yeah, everyone started scanning all over the place. Pretty much every WAF vendor or user set up their own pattern, and we did too. The first version was something like that. So, okay, we just match gndi, which is the entry point of the bug in log4j, and then pretty much everything that follows. We test it. Okay, it's fine. It triggers a little bit. No obvious pattern of false positive. Okay, good to go. We can ship it. And yeah, it worked well. Very quickly, however, the attackers tried to find bypasses for that. So the first one they found was they could use a different schema. The initial PLC used LDAP to perform the RCE, but actually you could use another schema, so they just did. In our case, we were not really looking at LDAP, so we didn't really care. But then they decided to step things up. So they started to use the string interpolation features of log4j to obfuscate their pattern further. So, okay, we need to complexify quite a bit the pattern. So every single character we had before became this whole mess to support some amount of obfuscation. Then attackers decided to step things up further. So, okay, now you have completely spurious blocks that are just going to disappear. Okay, we can expand the pattern further. This is becoming a bit unwieldy. For each character you have in the initial pattern, you have this whole mess there. And attackers just got crazy. This could either be the most complex waffle ever, or we need a different type strategy. So when we saw that, we basically tested two rules. One monstrosity that could deal with that, or something much simpler. And we are shocked, but this never triggered the false positive. Like, that's why we're telling you that you need to test rules, because this shouldn't work. And, yeah, the last bypasses we found at the end were attempts to use non-ASCII characters. So here, like, log4j would do some kind of unicode normalization. Yeah, at this point you need to do the same. And that's expensive. Yeah, and when we put this in production, it triggered roughly half a million triggers in a week. And that was before the acquisition of Datadog, so at a much smaller scale. We told you about how you design a rule, but there is a greater framework behind it and some constraints. So let Emmanuel tell you about the dilemma of building a WAF rule. Yes, so when you build a WAF rule, we try to kind of display this into a graph. On the horizontal axis, you can have a very broad rule that will catch everything, or a very specific rule. And on the vertical axis, you can have either a rule that's very easy to bypass, but doesn't give you too many false positives, or here on the top, it triggers a lot of false positives, but it's hard to bypass. All right, based on that, we try to define a max amount of noise that we're willing to accept, meaning if a rule starts triggering more false positives than this threshold, we're not even going to put it into prediction because it's not worth the hassle. Okay, now an ideal rule we could try to build would be something very broad that's going to catch every XSS attack that we're getting. Dope. And it doesn't trigger too many false positives and it's not too easy to bypass. All right, it's right in there in the middle. On the other side, you could also try to build a rule that's very, very specific, meaning it could only target a very specific XSS vulnerability for Jupyter notebooks. And same, not too easy to bypass and not too many false positives. Dope. Well, that would be an ideal rule because actually what happens most of the time when you try to build this rule is you end up right there. If you do a very broad rule, you're going to have a lot of false positives and if you do a very specific rule, you're going to be bypassed very easily. So what happens? Most of the time, you're going to be in this yellow area right there, the space of operation. And what you want to do, ideally, is to be right there in the middle. So you are doing, kind of, having the best of both worlds, so to speak. All right, so we've talked about how we don't want too many false positives because they are nasty. Well, let me tell you or kind of remind you why we don't want them. First, they are going to create an alert fatigue. So, yeah, there is nothing worse than you come into work and you see 10,000 plus alerts. What do I do with this? It's not worth looking at it and it's not actionable. Second reason why. Well, it can have a business impact. If you have rules in blocking mode, you might be blocking legitimate customers with a wrong setup. And if you're blocking customers, you're losing business. If you're losing business, you're losing money. So you don't want that either. And the last reason why you don't want false positives is because you might end up collecting PII by accident. Meaning you might collect some private information like addresses, emails, phone numbers. And this might end up in your log triggers. And because of that, you're going to have a security issue on your hands. So, yeah, you don't want that either. Overall, what you need to keep in mind is that it's all about finding this compromise. You want a rule that doesn't have too many false positives but still brings you value. All right. In all this time working on false positives, at Datadog, we've been able to see a bunch of them and we've tried to classify them into different types of families. The first family we've encountered most of the time is based on what they are. Meaning you get a bunch of triggers coming from free text. For example, you're running an application like Stack Overflow. You have a bunch of people pasting SQL injection all the time because they're asking questions about it. And this will trigger your WAF if it's set up in a way where it looks at free text. Second family you can have is if you're running any type of infrastructure that's having an admin panel, running SQL queries against your DB. This is going to look like SQL injection to your WAF. So let's say you're running phpMyAdmin that could happen most of the time. And also, if your application is relying on some concept like you're doing a lot of queries all over the place. For example, at Datadog, that's an issue that we have. We're running a ton of queries everywhere and it looks like SQL injection a lot of the time. So what do we do with that? Most of the time, when we run these queries, they have the keyword query in them. So we decided to pass list the word query to get rid of those false positives. And different type of rules are going to be sensitive to different type of false positive families. So you have to kind of look for them. For example, if you manage to detect some false positive based on the free text, what you can do is just pass list free text for some of the rules that trigger on them. We've talked about families. So now, how do we catch them? Because it's all good and fun, but how do we actually find them in our application when we have 10 plus thousand triggers? Well, you can do a bunch of statistics. So yeah, that's where the ML engineer comes into the room and tell you you should do statistics on your triggers. You can look at application or trigger trends. So what I mean is, let's say you're... you can look at your global traffic trends and see how many queries you're getting. And then what you can do is look at your trigger trends. If you have a rule that has a traffic that follows a lot your global application traffic, then it's probably a false positive here. We took an example of something with your data dog here. Yeah, you have a rule here, the yellow rule, that's triggering a lot of the time. It's like, I don't know, you cannot really see it here, but 250k triggers most of the time and across all days, every day. So that's where we're like, okay, we have a false positive on our hands. And here, on the other side, you can see here a purple bump. It's actually a security scanner and this is a rule that works perfectly fine. You can see it's not spread all over the place. If you're in doubt and you don't know if the trends that you're seeing are actually kind of matching the trends of your traffic, you can also look at the IPs that are triggering your alerts. If you have a very broad range, meaning everyone that's coming into your application is actually triggering your rule, you also have a rule that's having a false positive issue. And on this side here, I decided to kind of show you what a Nelfy-ish traffic would look like. So you have a bunch of bumps, ups and downs. It's not super regular, so this is typically what Nelfy rules would be outputting in terms of number of triggers. All right. Now let's take it a step further and let's see if we can actually do any kind of machine learning path processing. Yeah, you can start with embeddings. So I don't know if any of you are familiar with embeddings, but they are used, for example, in LLMs. So it's very trendy at the moment and you can use them to... basically use them as a hash function. You give it a payload, so it could be any type of string, and then it will give you back a vector of numbers. Here, it's going to be much larger than a 2D vector, but for the sake of this example, I kept a 2D vector. And what you can do is, you put it in some kind of graph. Here, okay, we put it there. Then, as we have a new payload coming in, that we know is also a false positive, we also put it through the embedding function and we get a new representation. And they are kind of clustered together, so we can kind of define a false positive area, a false positive cluster. And what this means is that when you have a new payload coming in and it's actually a real trigger, you're able to see it, because it's further away from all the false positive clusters you've been able to build. So you can kind of deduce false positives or new false positives based on what you already know. All right, old fun games, but if you're lazy and you don't want to do all this manual clustering, it's very cumbersome, you can do some more fancy things. So you can do classification, for example. You can use machine learning models like the classic old-school ones, or you can even use OpenAI LLMs, if you feel like it. If you do that, some of them will work out of the box, so it's super nice, and some others, if you want it really tailored to your use case, it's not going to work, so you will need to fine-tune them. And let me tell you, this is a hassle, like we've tried, and this is very tricky to do. You need to build a legit data set, so a lot of real triggers and a lot of false positives to actually make it make sense. And here, I took a plain example that we had when we did a trial. So we gave it an embedding, a bunch of payloads, and we picked an OpenAI LLMs, we fine-tuned it, and we gave it an actual SQL injection payload, and we were like, OK, what is this? And it replied, it's a true attack. Dope, OK, it's working. And then we did the same thing, but we just put a comment after, and it was like, oh no, no, this is not an attack, this is actually just someone randomly coming to your application and pasting that. So yeah, this is a blatant case of false negatives, and this can happen a lot. So if you're going the route of doing some fancy machine learning to deal with your false positives, just try to build a good data set. And yeah, it's just fancy statistics, basically. All right. What if we talk about the blind spots of the WAF now? So that's the part of the talk where the security vendor tells you it's totally fine, the product doesn't work. No, more seriously, WAFs have a problem with obfuscation. If you hide your payload, it's going to go through. And this is mostly because of what the internet is, which is a bunch of RFCs from the late 80s, early 90s, and all of the weird implementation bugs we had since then. And as a vendor, you can only really easily find the first ones. What are we talking about with, like, those weird bugs? You have a web server that I'm not going to name that happens to perform recursive decoding of URLs and support non-serial syntax. What this means is that you have this monstrosity here and it's going to be converted into an open bracket. Why? Because, I guess, some engineers hate us. SQL. That's great. It's a language. It's standardized. Every database engine is using the same. Right? No. No, of course not. MySQL decided to make some commands conditional. You have this command and in specific version of MySQL, it's not going to be a command anymore. Thank you. Last but not least, you can't define a list of value in a URL parameter. Like, it's just not supported by the other specs. So, if a developer wants to do it, of course, they only send it in the body. That's what it's there for. No, of course not. Every single web server does something different and passes, like, turns an array of parameters into a list. The best way to deal with this kind of obfuscation is to work around it completely. We have one advantage as defenders, which is that we know what the application on the other side of the WAF is. We have some insight. We know that we could know the language, the framework, what it's expecting. And using that, you could tell the WAF to decode the incoming parameter just like the application would do it. It does not mean that we would be able to decode everything. But in practice, you don't care. Because if the application can't decode a parameter, then the parameter can't harm it. It's not perfect. Specifically, it won't work if the parameter is integrated by something else, so specifically XSS, where the final target is a browser. But it's very effective against all kinds of URL encoding, HTTP shenanigans. Like, if you can just extract what the application is going to see, then you're golden. Moreover, another problem WAFs need to deal with is performance. The way most WAFs are set up is they add their latency to the response time of your application. Meaning, if your application answers in, like, two milliseconds, and you spent a lot of resources to optimize it, and the WAF just barges in and adds, like, 100 milliseconds of latency, that's unacceptable. So WAFs need to be able to fit within those constraints. Moreover, even if you're not under attack, we notice that even a small minority of long payload is enough to tank the performance. Like, surprisingly little. What this means is that you have a few constraints that WAFs are never really going to be able to work around of. So, for instance, if your WAF is not passing the body, and the application is expecting a large JSON payload, then all the attacker has to do is to put the attack at the end of the payload, and they're in. Some WAFs also have some constraints on the time they are allowed to take. And if they start taking, like, let's say more than five milliseconds, all right, they disconnect, they are like, there's too much impact. And all an attacker has to do is to increase the load on the WAF just by sending a bunch of requests, and, yeah, they're in. And, yeah, finally, the obfuscation, the WAF can do it. It can try to parse the parameter as a browser would do it, but it's expensive. So you need to figure out how do you want to spend your budget. And you might decide, okay, this decoding would be very effective, but actually if I use it on all of my rules, I'm, like, spending half my time just doing decoding and not actually running rules. There are a few solutions to that, such as running the WAF async. They all have, like, terrible problems, from not being able to block to you could direct all of your traffic to some kind of cloud infrastructure, but then you're adding latency, you're saying all of your traffic don't know where. So, yeah, that's kind of terrible. Finally, WAF, and I'm going to blow your mind, don't know what they don't see. So if you have an attack that the WAF don't catch, the WAF won't be able to tell you that you are under attack. What this means is that to be effective with WAF, you kind of need to do threat intel. You need to be able to do quick and quiet deploy of rules to be able to know what's happening in the wild. Doing some kind of shadow deployments. The scale at which you do that depends on what you can do. Like, it can be an only pot, but then you're mostly going to catch against the noise of the internet. You may be able to do it on your internal services, but, yeah, you'll get a better idea of what an actual attacker is going to do for your kind of application. And if you're a vendor and can work with it with your customers, you can even deploy it in customer environments. And that's amazing, because then you see a very broad diversity of attacks. Like, you see what the actual threat landscape is like. And when you do and you catch someone, WAFs are really good at leveraging mistakes. If you find any identifying pattern in an attacker, you can leverage it. Be it user agent, they're using this old version of Firefox. All right, I'm just going to match everything from that. It could be the IP or the range of IPs. It could be the domain they're fetching their attacks from. It's very common for accesses to load the payload from some given domain. Or, and that's the best one, typos. The attacker does a typo. All right, I just want to match all of the typo headers. And then once you have all of that, you dump all of the attacker traffic and you burn it all at once. And yeah, destroy that toolkit. So, we talked a bit about what WAFs are, what their issues are, what the false positive, false negative, what they're good at. Let's talk about making them better for end users. The first and most important point is you need to embrace the strength of the WAF and stop seeing a WAF as a protection tool. It won't be very good at that. If you want something to catch every single exploit going to your application, there are things, there are products that do that. There are RAS, there are IAS. There are some solutions, but WAFs are not it. What a WAF is, is a monitoring tool. A WAF will tell you that you're under attack and give you a feeling for the kind of attacks that the attacker is sending. It won't give you everything. If you wanted to do it, you can. It's called, like, here, this rule, trade secret. You just match that star. You can get everything. It will be totally unusable. Next one, rule testing. You can have a good turnkey experience in a WAF. But for that, rules need to have been tested on every single kind of workloads. And this requires massive scale. On top of it, whoever is doing the rule qualification will need to decide how much noise is good enough. And that's going to depend from a deployment perspective, from a company perspective, from a... yeah. It even changes on an engineer basis. The best way for someone to guarantee that the rule is going to work is to do some kind of shadow deployment, meaning running the rules on your environment without blocking. And, yeah. Doing all of that, you need to make sure not to catch any PII because otherwise you're in trouble. All right. Next up, you can try to leverage your application context. Meaning, if you're able to give data about your application to your WAF, like, telling it which language you're running, telling it which framework you're using, then, in that case, you'll be able to increase the precision. Let me give you an example. You're running a JavaScript application. You're receiving a bunch of PHP attacks. Well, you don't really care about those. They're not going to hurt your application. So, what you need to do is just discard those. If you're running some kind of PHP, for example, the SilverStripe framework, it was vulnerable to XSS in older versions. Well, if you're not running, if you're running up to the latest version, you also don't care about the alerts that are targeting the older version. So, yeah. If you're able to do that, you'll increase your accuracy. And one other side effect that can be good for you is you're also able to detect threat actors that will be sending, for example, Java attacks to your app when you're not running any Java, and you can kind of increase the attention that you're giving to this malicious IP and gather a bunch of threat intel on top of that. The only downside is it's going to be a bit challenging, meaning you have to have your security team work with your engineering team, and God knows it can be tricky to do sometimes. So, if you're able to do that, you can build this feedback loop that will be improving greatly your experience with the WAF. And the last element that you can try is to tune the response to the attack, meaning if you're able to catch a specific IP that's been targeting your application for a while, you could dynamically roll out a new rule set for this specific IP and catch more attacks coming from it, and you could catch everything and see what's coming up. And, yeah, if you're able to do that, and on top of that, what you could try, if you're unsure if the actor is actually malicious, we should be able to enable different types of responses. First, we should be able to have a capture and then only block after. Remember, we talked a bit about how we can do some analysis of false positives. If we're also able to leverage that to feed that back to the WAF and build dynamically a bunch of passive rules so we don't have as many false positives, it's even better. We could be even more confident when we actually enable the WAF in blocking mode on some rules. All right, this is our final takeaways. If you're a defender, look at your WAF more as a monitoring system than as a protection system. You should try to launch your false positives because this way you will be able to leverage the actual alerts that you get. And if you're building some kind of rule set, make sure that you keep in some flexibility for your engineering team. Meaning if you do very restrictive type of rule set and as soon as your engineers are changing the app, they're breaking everything, it's not worth it. If you are a vendor, well, I think it should be our collective mission to propose to our users a very low noise rule set. And then also support them in their efforts to actually analyze their triggers and the trends that they have. And if you're collecting any type of threat intelligence, please share it across all of your customers so everyone can benefit from it. And last, if you're an attacker, well, you're in luck because there will always be bypasses to the WAF. We've talked about them because of the WAF's nature. So keep in mind that you should probably rotate your infrastructure because we will leverage all the mistakes that you make and if you don't rotate, we'll catch you and we'll thank you for that. And then if you have to invest in one type of application, please only invest in ambiguous interpreted obfuscation. HTTP is worthless. Alright, we're at the end. Thank you for listening to us. applause music music music music