Security

BehaviorLock pins what your tests taught an ASP.NET Core endpoint — and blocks the rest

DEV Community: #dotnet vadim albarov
Security

Vadim Albarov's open-source MVP BehaviorLock records what each ASP.NET Core endpoint touches during integration tests — SQL shapes and outbound hosts — then blocks anything absent from the committed profile at runtime. The point: no signature list, nothing to update when a new attack appears.

Key points

  • Three modes: Learn records, Audit reports unknown access without blocking, Enforce returns 403 on anything new.
  • `behavior.lock.json` pins normalized SQL text (values replaced by `?`) plus method, scheme, host and port of HTTP calls.
  • About 2-3% throughput loss and at most 0.04 ms latency difference on local SQLite, per the repo's README.
  • A MySQL backslash escape made version 1 read 58 of 8,334 injected commands as legal; after the fix, 0.
  • Declared blind spots: broken access control, business-logic bugs, XSS and DoS keep the same query shape.
  • Setup is three calls: `AddBehaviorLock`, `UseBehaviorLock` on the DbContext options and the `UseBehaviorLock()` middleware; no NuGet package yet.

Real-world use

  • An orders API whose detail endpoint must never touch the Users table, even when a debug flag appears.
  • A taken-over payment dependency that starts copying large orders to a host nobody has seen before.
  • SSRF attempts that reach for a metadata address or an unexpected port on an allowed host.
  • Endpoints where each legal path is covered by an integration test before Enforce is switched on.

This summary was generated by the agent from the original post on DEV Community: #dotnet. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message