Using LLMs to Secure Source Code — Eugene Yan, Anthropic
AI Engineer · 21 min · 270 sentences · from YouTube's caption track
Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.
- 00:01[music]
- 00:12Hi, I'm Eugene U member of technical staff at Entropic.
- 00:15Um, I've spent the last several months with working with security teams and claw to find and fix vulnerabilities in codes and systems.
- 00:21So, I want to share with you what we've learned as much as we can.
- 00:24Before I get started, quick show of hands.
- 00:26How many of here here are security engineers in your day job?
- 00:31Okay.
- 00:31Okay.
- 00:32How many of you here are engineers in your day job?
- 00:34Oh, sweet.
- 00:35Okay, great.
- 00:36I have better understanding of how to give this talk now.
- 00:38Um, security engineers in the room.
- 00:40Please don't boo me if I oversimplify things.
- 00:42I want to get this message out to as many people as I can.
- 00:45So, first I want to share with you three highle trends that we are seeing in terms of model capabilities, right?
- 00:50Number of vulnerabilities found um and where the bottleneck is shifting to.
- 00:54Then I want to distill the lessons we've learned from working with dozens of uh organizations to improve their security posture as well as the bottleneck that you might encounter and how you can try to address it and prep for it.
- 01:03And finally, I want to share how you can get started this week with links to resources.
- 01:09So why do we care about so much about cyber security now?
- 01:12Um time horizon benchmarks track the length of time an AI model can complete a task measured against an actual human doing the task.
- 01:22Um so we all know about the meter eval task.
- 01:26You know how how much knowledge what a engine can do.
- 01:28The UK AI security institute has a cyber security version of this.
- 01:32You know these tasks require identifying exploiting security weaknesses in target systems and you know testing skills like reverse engineering and web exploitation.
- 01:40So in this chart we see that models are able to increasingly do longer cyber security task.
- 01:45Um but what's also interesting is that you kind of see a step jump against the previous regression line.
- 01:51So these models are a step improvement in capability.
- 01:55And what does this step improvement in capability buy us?
- 01:58Recently Mosilla Firefox published a number of security bug fixes they made each month.
- 02:04The average in 2025 was about 2020 20ish.
- 02:08And then you can see in February and March it kind of 3xed to about 60 and 70.
- 02:13And then in April it 7xed to 400.
- 02:18So what this means is that what's happened in April is 20x of last year's average.
- 02:24Um they attributed about twothirds of this to mess preview about 271 which shows that frontier models can help defenders like yourself find and fix vulnerabilities at scale.
- 02:37We also uh what are some notable vulnerabilities?
- 02:40Hands up.
- 02:40Who here remembers lock for shell?
- 02:43Anyone?
- 02:43Anyone was here over the December holidays like scrambling to patch this seu?
- 02:47So log for shell um is a bug in the Java logging library.
- 02:51If an attacker sends a string, you log it, the attacker can run code on your system.
- 02:57The Belgium defense ministry was breached within days and a fintech platform uh leaked 2 million users data.
- 03:03And then before that we had heartbleleed which is an a bug in open SSL.
- 03:06You know so much of the of the internet runs on OpenSSL and we we all know what impact it had.
- 03:13This is entropic sharing of our own work scanning more than a thousand open source repos.
- 03:19Um from 23,000 candidates uh 6,200 of them were rated as high or critical and at the time of the update 1,600 of them were reported to maintainers and about 100 patch upstream.
- 03:32We shared our observation that finding vulnerabilities now is quite straightforward.
- 03:39The bottleneck has now shifted to verification, triage, and patching.
- 03:43And I want to share with you everything we've learned about that so you can get ahead of it.
- 03:48So how do we do this in our own systems and code bases?
- 03:52Um, two words, agentic harnesses.
- 03:54I'm citing Mozilla again, and this was even before they worked with me preview.
- 03:58I'm going to read off the screen here.
- 04:00Early experiments showed that some promise, but the high rates of false positives made it impractical to scale.
- 04:08But the introduction of agentic harnesses that can reliably detect security issues has changed this.
- 04:14Right?
- 04:15These models and harnesses together can find real bugs and dismiss nonreproducible speculation.
- 04:23So the harness and the model working together can get a lot of work done.
- 04:29We found that most teams converge in approximately these six steps.
- 04:34And a big chunk of my talk is going to be about these six steps.
- 04:37Right?
- 04:37Right.
- 04:37The first two steps are set up, right?
- 04:38You do a bit of upfront investment per codebase.
- 04:41How many of you here know what a threat model is?
- 04:44Amazing.
- 04:45I love that.
- 04:46Uh a track model is some kind of like kind of a system design, but for your codebase or system, what are threat vectors?
- 04:51So, this helps you decide what are the vulnerabilities in your system that you care about.
- 04:56And then also, we also want an isolated sandbox where you let your model run possibly untrusted code or you let your model deliberately detonate proof of concepts of exploits.
- 05:06I'm going to call them pox to confirm that they are true positives.
- 05:10And then the next four are loop where you know we have discovery that identifies vulnerabilities.
- 05:15Verification confirms that they are real.
- 05:17We have triage.
- 05:18You know you can't give a developer 100 vulnerabilities.
- 05:21You got to identify the top 10 or 20 critical and high so they can focus their attention and then you can patch patch the bugs.
- 05:28So now I'm going to talk about each step.
- 05:30Now to make things concrete I want to share with you how they apply on a hypothetical system.
- 05:35So this is order service.
- 05:37Order service you type in a ID and then you look up an order.
- 05:41So what kind of v vulnerabilities might we find in this?
- 05:44Um the first step is the threat model.
- 05:47So why does this matter?
- 05:48So several teams if you look at a code right finding have found that having a well doumented thread model really increases your true positive rate to 90%.
- 05:5890% is outstanding if you ask me.
- 06:00I think anything above 75 is is great.
- 06:02That's where you want to aim for.
- 06:04Now to put it another way, one CISO said this, the model has great context of the code but poor context of the system.
- 06:11And why does this why does this happen?
- 06:13It's the whatever the model can read, the model will understand well.
- 06:18But there's so much information that the model cannot read.
- 06:20Why did the senior designer design the system this way?
- 06:24What are all the vulner vulnerabilities that on call has been fixing that has not been written down?
- 06:28All of this is now implicit context in your head, but you need to write it down somewhere, maybe in a threel to help the model be a better security engineer.
- 06:37So we can work with models to build these thread models.
- 06:39And the track model is really just a document, right?
- 06:42First, we can bootstrap a trap model, give the model access to all your documents and code, even past code commits, past patches that were made and what CVE they were patching
- 06:51and you can ask the model to infer, hey, what possible what other CVs have not been patched, right?
- 06:56So a model can do that.
- 06:58Then after the next step is that you should ask the model to interview the expert on the system right what are some things that could happen that we didn't plan for or what are some things that we actually don't
- 07:10need to worry about for vulnerability because maybe this is an internal VPN only app or there's a compensating control elsewhere a lot of this is not in the code right if you look at your codebase it's not there but it needs to be written down somewhere so the model can benefit for it
- 07:24so here's an example thread model of order service right you know the key asset is the data you know contains customer PII and the entry point is the orders API
- 07:34we can also see that the model has suggested some possible threat vectors like SQL injection and that the fact that you could call this API without any form of authentication
- 07:42then the second step is the sandbox so isolation and reproducibility in some cases we may be running untrusted code in some cases we may be asking the model to deliberately
- 07:54create exploits so we want some isolation ation um to prevent the model from doing bad things.
- 08:00So this isolation doing bad things could be data exfiltration or you know dropping things in production and of course uh you you want all of this to be running in a VM without egress and of of course without your cloud credentials.
- 08:13The second thing we want is reproducibility.
- 08:16So a lot of times uh you may find that the model may find a bug because you were using a old dependency or you want you want all of your agents to be starting from the same baseline container
- 08:27so that your agents can verif can can can run everything in a partners in the pipeline.
- 08:32So now building a repro uh representative sandbox of your system is actually quite difficult but the capability is quite useful.
- 08:38I think here's one team we worked with.
- 08:40They quoted the biggest ef the biggest lever we had is having the model test beds essentially sandboxes with live systems and where they can run and detonate the pox to confirm that they are true positives.
- 08:52So how would a sandbox for order service look like?
- 08:56Well this is a simple sandbox uh three docker images connected together.
- 09:00One for the app, one for the posgress database and one for the radius cache.
- 09:05And on the right we have the security agent uh which sits outside the target boundary trying to probe the app via HTTP.
- 09:13Now that we have the setup done we can now move on to doing the work of discovery finding the vulnerabilities.
- 09:21So the first is no so what are some there there are three things that matter a lot and there's no surprises here.
- 09:27The first thing is really context engineering.
- 09:29You're going to give the model all the context as much context as you can.
- 09:33If the if it's written down and if you share with the model, the model can find it.
- 09:36The model will be a better security engineer.
- 09:39You'll improve your vulnerability coverage.
- 09:41You'll reduce your false positive rate.
- 09:43The second is to have simple prop simpler props.
- 09:47Um, how many of here have found that as models get better, you actually need to remove from your prompts.
- 09:54That's what I found with every new model version of StepJum, I actually have to cut my prompt size by maybe about 50%.
- 10:00Right?
- 10:00So as models get better your prompts need to be less and less specific prescriptive even while you know previous models you might ask the model to look out for specific category classes
- 10:10but for newer models you can just probably say something like look for where untrusted data hits the trust boundary and the model is very good at inferring this.
- 10:20Finally give the model tools.
- 10:21So one example we had a pentesting team.
- 10:24They give the model tools to check the response to to query the API, check the response, read the logs, read the source code.
- 10:32Now this is just like the tools that you give a regular security engineer, right?
- 10:36A lot of times you expect the model to just read the code.
- 10:39That doesn't quite work.
- 10:40Allow the model to be dynamic to read the tools uh to to run the tools.
- 10:44And when they did this, their true positive rate was almost 100%.
- 10:48because the model could actually verify in the loop.
- 10:52So here is the get API for the order service and it's just five lines of code.
- 10:58Can anyone here spot the vulnerability?
- 11:01You can shout it out you guys.
- 11:05Exactly.
- 11:06So this is what the discovery agent flag right you know in line four we built a SQL query via Python string interpolation.
- 11:13So the user input input flows straight to the SQL query right and that means that someone can inject a SQL query that excfiltrates data from your database.
- 11:20This is code that I would have written right as me as a non security engineer it's just a very I just write the simplest code possible and this is how it would look like current models are very good at detect spotting simple stuff like this.
- 11:34So after discovery so we have maybe a thousand let's say 100 vulnerabilities we may have not been able to confirm them.
- 11:42The next step is verification.
- 11:44So if you think about machine learning, discovery optimizes for recall.
- 11:48Find as many vulnerabilities as possible.
- 11:51Verification optimizes for precision.
- 11:53Of the 100 vulnerabilities we found, how many of them are truly optim uh truly exploitable.
- 12:00So we have them both working separately.
- 12:02So we found that it's helpful to have these two steps separately, right?
- 12:05Because when the discovery agent is trying to verify its own work in the loop, trying to debate against itself in the loop, it may actually self censor and this may actually hurt recall.
- 12:15Um, and when building the verification agent, it's helpful for the verification agent to be independent and adversarial.
- 12:20Independent means that the verification agent doesn't see the reasoning traces, doesn't see all the work that the discovery agent has done.
- 12:28All the verification agent gets is the vulnerability and it approaches it from an adversarial point of view.
- 12:33assume that this vulnerability is false, try to confirm it's false or confirm it's true.
- 12:38So this sets the this sets a very high bar for the vulnerability which reduces the false positive rate.
- 12:44And also if you have invested the time in building building a representative sandbox um have the verification agent build the p detonate the pock to confirm if the ver the vulnerability is true.
- 12:58So in this case back to order service our verification agent is confirming the SQL injection right in a fresh container and this is why we have everything containers the verification agent is only given line number four here's where a SQL injection could happen
- 13:12and the verification agent actually tries just runs the corl command and the verification agent can see all the customer pi that has been exfiltrated.
- 13:21So now you have confirmation that a SQL injection can work.
- 13:26So after discovery and verification, we've maximized recall, we've optimized for precision, the next step is triage.
- 13:34So a lot of this may truly fire, but some of these are bug correctness issues.
- 13:38They have very low business impact.
- 13:41So across multiple teams, they shared that you can lose trust with product engineers by sending them all the vulnerabilities that are true, even those that are medium or low severity
- 13:51because those engineers can't cope.
- 13:53And as we've seen so many times, the scars resource now is engineer attention.
- 14:00So imagine you're a product engineer.
- 14:01What are the kinds of vulnerabilities you want to actually receive and fix?
- 14:05So as part of this step, we can do dduplication, you know, cheap heristic checks or we can get a model to help you with clustering and dduplication.
- 14:12We should also consider the severity of the exploit, right?
- 14:15Uh one thing to consider is the magnitude of the outcome of the impact.
- 14:20What is the magnitude?
- 14:20Is it a ring zero magnitude or ring one magnitude?
- 14:23Um, and also the likelihood of it occurring, right?
- 14:25How many hoops does an attacker have to jump through to actually make that exploit?
- 14:31And this is where the thread model is useful to all.
- 14:33You can think of the thread model as just synonymous with context.
- 14:36Just give the model context about your business, right?
- 14:39So for example, compensating controls.
- 14:41If you have a firewall, something that was initially high severity could actually be low.
- 14:47On the other hand, if you know that your database is mostly customer PI data or healthcare data, a model might have have set that as medium severity, but it actually could be high because the the contents of your data are so sensitive.
- 15:01So in this case, we have on the left triage that the agent has done.
- 15:06The agent has said that this is high severity for these reasons, right?
- 15:10High impact, high likelihood.
- 15:12Now on the right after human review the operator has confirmed that you know has downgraded this to low likelihood and the reason why it's low likelihood is because we have an application firewall that blocks SQL injections
- 15:26and also there's the fact that the service is internal only it's only for internal I warehousing or internal logistics it's not it's never internet facing therefore the likelihood is low now you can imagine like how would the model know this this is not written in a codebase
- 15:39it may be available in a system design it may be available in your documentation, it may be available in your confluence etc. So this is the kind of context you need to provide to the model so that the model can get better at this.
- 15:52Now after that we close the loop patching to validate the patch you know we can build a patch and then we want to validate there's a ladder of sorts
- 16:00first the original PC has to stop working that's basic second the existing test suite should stay green no regression and then we can go further right we can have a fresh discovery agent try to attack the patch code again is the patch comprehensive enough
- 16:15and teams have found that by giving the patching agent such feedback um you can actually the patch quality improves greatly right and you know This is the generative verifier loop.
- 16:23Give your agents context, give your agents feedback, and they they can do the do their work.
- 16:27And finally, a human confirms the patch before it's been merged.
- 16:31So here's how the patch will look like.
- 16:32You know, in the first div, we update the code, it's a oneline fix where we move the variable out of Python uh and therefore we reduce the code of SQL injection.
- 16:41And in the second div, not only do we update the code, not only do we fix the system, we close the loop.
- 16:46We make sure that the next time we run this loop, we run this scan, these issues don't happen again.
- 16:51And this is really important when you're building the building harnesses, right?
- 16:54You're building loops.
- 16:55They're operational expense, but when you close the loop, they now become capital expense.
- 17:00You get better with each iteration you run.
- 17:03So you make clear the compensity controls.
- 17:04We have the application firewall and the fact that it's internal only.
- 17:08Okay.
- 17:09So the quick recap, these are the six steps and each step focuses on one thing.
- 17:14Track model provides context.
- 17:16Sandbox provides isolation and reproducibility.
- 17:19This is the baseline fundamentals that you need to have.
- 17:21This will carry throughout every scan.
- 17:24You have context and reproducibility.
- 17:27Then after that, the rest is really if you look at it, it's if you if you squint, it actually looks like an ML pipeline.
- 17:33Recall, precision, ranking, and closing the loop.
- 17:38It's a regular machine learning pipeline.
- 17:43Now, that's the technical challenge we have.
- 17:45There's another technical challenge we have.
- 17:47And as my previous director would say, non-technical problems are an order of magnitude harder than technical problems.
- 17:54So what are some other bottlenecks you might have?
- 17:57So imagine you have a process.
- 17:59What happens when you have one or two orders of magnitude more input?
- 18:04What is going to start to break?
- 18:05In the case of the harness, the scanning harness, you just have more engineering.
- 18:09You spend more compute.
- 18:11You pay more money.
- 18:12Things that can be solved with money are not really problems.
- 18:15But human attention doesn't scale.
- 18:18Your deaf, your product engineers and your security engineers, what if they don't agree on what high severity or uh critical severity is?
- 18:26You need to put them in a room.
- 18:28You need to write down all these rules so that everyone agrees.
- 18:31And you know your threat models, they're all stuck in people's heads right now.
- 18:35Someone needs they need to be interviewed maybe by a model or by someone else and write all that trap model down so that now you can have agents help you.
- 18:43And finally, you know, patching patch patch review.
- 18:46Um, I still don't know of many companies that gone through fully automated patch review, especially when p uh patching security issues.
- 18:54So, here are some organizational bottlenecks that you might hit and what you can do.
- 18:59The first thing is vulnerability routing.
- 19:01So, if you maybe get a dozen vulnerabilities a month, you can probably curate them.
- 19:05You know, email them to specific teams, assign Jira tickets.
- 19:08When you have hundreds, you can't do this.
- 19:11And this can really be as simple as you know sending it to the code owner etc. um or or the service owner and it doesn't really need an LM in the loop.
- 19:20Then second thing is severity calibration.
- 19:22The the one hard thing we found is that product engineers and security engineers red team blue team they may not agree on what high severity is and all this requires a lot of your business context.
- 19:32I really think it helps to have everyone discuss and write it all down once and for all agree upon that that you can send that to agent and finally the patching bandwidth.
- 19:42Um I'm sure no one writes very few of you here write code by hand now but it's also very challenging for you to just be given the vulnerability and try to implement a patch even with LM assistance.
- 19:54you definitely want to be moving towards AI generated patches and then have the human loop verify and you know generate the patch reattack the patch.
- 20:02Okay, if you only remember one thing well here are the three things you want I want you to remember.
- 20:09I would like to you start now please start with open source dependencies start with whatever you're comfortable with.
- 20:17Two I want to teach you how to climb the learning curve.
- 20:20Don't try to aim for automation immediately.
- 20:23Right?
- 20:23Start interactively.
- 20:25Do it hands on the wheel with uh claw code or your favorite ID.
- 20:28Doesn't matter.
- 20:29Learn where you get cut.
- 20:31Learn what kind of context you're missing.
- 20:32Learn where precision is low.
- 20:34Then third is don't just aim for scanning.
- 20:39Uh scanning is not the bottleneck.
- 20:41Verification, triage, and patching.
- 20:42And then all your organizational processes.
- 20:44Those are the bottleneck.
- 20:45Over there.
- 20:46I have a couple of resources.
- 20:47We have cloud security to scan your codebase, validate findings such as patches.
- 20:51We have a blog.
- 20:52We have open source repos for with that includes the interactive skills and autonomous harnesses and all you have to do is to run this few steps to very quickly get hands on the wheel and in it if you look at step five you have the harness and you can just customize it.
- 21:08That's all I had.
- 21:09Thank you.