Sources indicate that in 2018 and 2019, attackers needed 63 days on average to exploit a vulnerability after its patch came out. Google's Mandiant team measures this every year. In 2021 and 2022 it was 32 days. In 2023 it was 5 days. For 2025, the estimate is minus 7 days.

A negative number means that the average attack starts before the patch exists. (Related: Average Retirement Savings by Age: Are You on Track?...)

Recent findings suggest that most of that drop happened before AI did much in security. Now add AI. (Related: Is Social Security Taxable? How to Calculate What You O...)

According to recent reports, both of these are the defending side, with a disclosure process and time for the vendors. But a skill like this does not stay on one side. I think we should blueprint for a world where an automatic scanner can find an unknown hole in almost any system, on any day, for little money.

Industry observers note that now look at how we defend. Someone reports the hole. Someone writes the fix. Someone reviews it, tests it and deploys it. There is a person in every step, and the whole loop takes days when it goes well. When the attack takes hours, the engineer has no time to react. It does not matter how good the engineer is.

So I asked another question. What kind of defense needs no time to react?

Recent findings suggest that it must work without knowing the attack, because the attack is fresh. It must work without a person, because no person is fast enough. I see one design that fits both: do not look for bad things at all. Know what the system does when it works correctly, and stop everything else at the moment it happens.

According to recent reports, I cannot build that for an operating system or a browser. I can try it for the layer that I write myself: the API. The result is BehaviorLock, an open source library for ASP.NET Core.

Recent findings suggest that an API endpoint is a boring thing, and that is its strength. An endpoint that returns one order runs one SELECT on one table. It did that yesterday and it will do that tomorrow. It has no reason to ever read the Consumers table, and no reason to call a host it has never called.

So BehaviorLock writes down what each endpoint does, and blocks the rest. "Proven" has a simple meaning here: a test sent a legal request, and this is what the endpoint did.

A part of the file from the sample app:.

Each line is one thing that the endpoint may do:.

Sources indicate that the guard has no list of attacks. It cannot be out of date, because it has nothing to enhancement. A new attack technique is still blocked on its first day, as long as it makes an endpoint touch something new, take a new kind of caller, or return more than it ever did.

Version 0.3.0 is on NuGet, for .NET 10 and .NET 11.

It has been revealed that that covers EF Core and every HttpClient of the process, also a client that a package creates by itself, and each redirect hop. An app with Dapper or plain ADO.NET wraps its connection, and the code that uses the connection does not change:.

A second package, BehaviorLock.StackExchangeRedis, does the same for Redis commands.

The repo has a small shop API with weaknesses built in on purpose. The tests run each attack twice: with the guard off, to prove the harm is real, and in Enforce mode, to prove it is stopped.

Twelve rows, and the guard has no rule for any of them. Three rows show the point best.

The debug switch. Someone left a ?debug=true in the order endpoint, and it returns every user with their password. There is nothing bad in that request. No quote, no payload, nothing a signature could match. The guard does not look at the request. It sees that an endpoint which reads Orders now wants to read Owners. The request gets a 403, and the log has this line:.

The dependency. The payment client in the sample stands for a package that was taken over. It works as expected, but it copies every order above 1000 to another host. The tests place an order of 120, so no test ever sees that code run. This is the closest thing to a zero-day at this layer: bad code inside something you trust, on a path that nobody has looked at. In production the first large order tries to call a host that is not in the profile. The call never leaves the server.

According to recent reports, the missing role check. GET /admin/orders only asks for a signed-in user. Somebody forgot the role. The tests call it as an admin, because that is the legal use. So the profile notes caller: signed in, role admin, and a normal user gets a 403 from the guard. Nobody wrote that rule. The tests wrote it.

The cost is small. In my load test on a local SQLite file, which is the worst case for the guard, the throughput in Enforce mode was at most about 4% lower than without the package. The latency percentiles differed by 0.3 ms or less. The check of a SQL text that the guard has seen before takes about 0.4 microseconds.

The blocking needs no person. That was the goal.

According to recent reports, learning fresh legal behavior does need a person, and that is on purpose. Tests never cover every legal path, so the default mode is Audit: report, but allow. The guard writes each unknown access to a pending file, and all instances of the app can share that one file. A person reads it and decides: this is a legal path that the tests missed, or this is an attack. Legal paths get a test and move into the profile. When the pending file stays empty, the endpoint goes to Enforce. Each endpoint can have its own mode, so this can happen one endpoint at a time.

If the guard could approve new behavior by itself, an attacker would teach it. So the human work did not go away. It moved. It now happens before the attack, in a pull request where the profile diff highlights that an endpoint touches something new. And it happens after the attack, in a review of what was blocked. It does not happen during the attack, when there is no time.

One thing can still go wrong at night: the guard blocks legal customers. For that case the mode is a setting that the running app reads again. A change from Enforce to Audit needs no deploy.

Industry observers note that A world where scanners find holes everywhere includes the hole in my guard. I had one in the first version.

To turn WHERE Name = 'alice' into WHERE Name = ?, the guard must find the end of the string at the same place as the database. The first version used the rule of standard SQL. MySQL, by default, reads a backslash as an escape. So take a query that is built from two form fields, send one backslash as the name, and send OR 1=1 -- as the city:.

Recent findings suggest that the guard saw two strings and the legal shape, WHERE Name = ? AND City = ?. MySQL saw one string, '\' AND City = ', then OR 1=1, and returned every row. The attacker did not need a single quote character.

Sources indicate that A backslash rule does not fix it, because MySQL and PostgreSQL can turn that escape on and off with a server setting, and the guard cannot see the setting. So the guard now reads each string both ways. When the two readings end at different places, it does not normalize the command. It keeps the whole text, which can then only match the exact same text in the profile.

I did not want to trust my own reading of the manuals again, so the repo has a test where the database is the judge. It builds commands from random pieces, runs each one on a real server, and counts the rows. A command that returns every row ran injected code, so its shape must differ from the legal shape.

58 of 8,334 is 0.7%. It looks small. A random test tries things blind. An attacker with a good model needs one of the 58, and will find it.

Recent findings suggest that the guard runs inside the app process. Two things are out of its reach. A raw socket or native code does not pass through HttpClient. And an attacker who runs code in the process can turn the guard off.

Sources indicate that the network sees both. And the profile already names every host that the app calls. So a small tool turns the profile into an allowlist for the network:.

In a recent development, it can also write a CiliumNetworkPolicy for Kubernetes. The network then drops every connection to another address, whatever code opens it. This list is for the whole app and not for one endpoint, so it does not replace the guard. The two work together: the guard is exact, and the network cannot be turned off from inside the process.

So this does not replace parameters, authorization checks or patching. It is a layer for the hours when all of those are late.

I do not know if the world of the first section arrives in one year or in five. I do think that "find, report, patch, deploy" will lose to a scanner that needs an hour. Something has to stand in the request path that needs no person and no update.

In a recent development, behaviorLock is my attempt at one piece of that. The code is at github.com/valbarov/BehaviorLock, under Apache-2.0. If you find a request that makes an endpoint do something new and still passes, please report it. SECURITY.md indicates how. That is the bug I most want to hear about.

If a scanner found a hole in your API tonight, what would stop the request before anyone on your team is awake?

→ Read original article