Skip to content

ADR: The one write a stranger can make

ADR: The one write a stranger can make

Status
accepted
Date
2026-09-03

The security page has said there is no rate limiter since it was written. This is not the limiter it meant, and that is the point.

In plain words

Creating an account was the only thing a stranger could do that the database kept, and each one costs about 120 ms of CPU to hash the password. Registration is now capped at 120 accounts per sliding hour across the whole site, counted without telling one visitor from another.

What that is worth: a developer sees a limit that works behind the edge because it never needs to know who is asking, and the organization bounds its bill and keeps the container responsive while everything other than registration keeps working.

Context

Ask a narrow question instead of a broad one: what can somebody with no account cause this application to keep?

  • GET everything. Reads, and they cost a query.
  • POST /api/errors/client. Writes into a ring buffer with fifty slots, each one bounded in size, and the ring is the browser's own so a flood of them cannot push server errors out of the operator's view. That was fixed in 1.0.0.64 and it is the shape this record copies.
  • POST /api/auth/register. Writes a row to AspNetUsers, in Azure SQL Database, and keeps it.

That is the whole list, and only the last one persists. Bids need an account, and a bid is keyed on the person and the vehicle together, so a signed-in visitor can hold at most one row per vehicle. Which means the number of rows anybody can add to this database is a function of the number of accounts, and the number of accounts had no ceiling at all.

The rows are the smaller half. Identity hashes a password on the way in, on purpose, at a cost measured here at about 120 ms of CPU. One container serves this site. A loop against this one endpoint is a hundred and twenty milliseconds of somebody else's CPU per request, which is a better attack on this site than anything else it exposes, and it needs no account, no session and no cleverness.

What the security page actually argued

It says:

Behind the edge, the origin sees one address for every visitor, so an IP-partitioned limit is a global cap rather than a per-attacker one, and because the origin is directly reachable an attacker can bypass the edge and forge whatever address they like.

Every word of that is true and none of it is about this. It is an argument about partitioning: any limit that has to tell one visitor from another is either lying to itself behind the edge or being lied to in front of it.

A limit that does not partition has nothing to forge. It counts registrations, full stop, and an attacker with ten thousand addresses gets exactly the same answer as an attacker with one.

That distinction was available the whole time and was not made, because "there is no rate limiter" was written once and then read as settled. It is the same species as the three findings in 1.0.0.61 through 1.0.0.63: a sentence that was correct about the question it was answering, left standing over a question it was never asked.

Decision

A sliding hour, counted across the whole site, of 120 registrations.

Sliding rather than a bucket that resets on the hour. A bucket hands the whole allowance back at a known instant, so an attacker takes it twice in two minutes by arriving either side of the reset. The window holds the times of the last accepted registrations and ages them out one at a time.

A refusal is not recorded. Only an accepted registration takes a slot. If refusals counted, fifty of them in the fifty-ninth minute would hold the window open for another hour, and a limiter that never lets go while anybody keeps knocking is the outage it was built to prevent.

Checked after the request is read and before the password is hashed. A malformed request should not spend the allowance, and a refused one should not spend the CPU, which is the thing being protected.

The refusal says nothing with a number in it. It says the demo is not taking new accounts and to try in an hour. A reply that reported how much of the allowance remained would be a counter anybody could poll, and the test asserts no digit reaches the words.

120. This site has never seen more than a handful of registrations in a day and most of those were its own tests, so the ceiling sits three orders of magnitude above real use. Nobody meets it who is not trying to.

What this costs, said plainly

While an attacker is spending the hour's allowance, a real visitor cannot register either. That is a denial of service, in the small, and it is the trade being made on purpose: an hour of no new accounts is cheaper than an unbounded bill and a saturated container, and everything else keeps working. Browsing, signing in, bidding, and every existing account are untouched, and one test exists only to say so.

The honest version of the alternative is worth writing down: with no limit, the same attacker gets the CPU and the rows and nobody is refused, because there is nothing to refuse them with.

Alternatives

A total cap on accounts. Simpler, and it bounds the bill forever rather than per hour. It also converts a temporary refusal into a permanent one: fill it once and this site never takes another account without a deploy. For a portfolio whose entire purpose is that a stranger can try it, that is the wrong failure to choose.

Per-address limiting. The security page explains why this does not work here, and it still does not.

A CAPTCHA. It would work, and it would put a third party's script on a page whose whole argument is that a reader can see everything it does.

Nothing, and say so. This was the position until today and it was defensible while the origin held no data. Accounts and a database arrived underneath it.

What is still owed

The window lives in memory, in one container. A second instance would get its own, and the site's real ceiling would be 120 times the instance count. That is correct for what runs today, one container, and it is written here rather than discovered later. A durable counter belongs with the origin lock, which needs a paid subscription, and those two are one piece of work.

Consequences

  • The only anonymous write this application accepts has a ceiling, and so, by the key on the bids table, does everything else in the database.
  • A visitor who has never seen it will never see it.
  • The security page's rate limiter paragraph is now half true, and its addendum says which half.

The window, read from this build:

/// <summary>
/// How many accounts this site will let strangers create in an hour, counted
/// across the whole site rather than per visitor.
///
/// <para>Registration is the only write an anonymous caller can make that
/// persists. Everything else a stranger can reach either reads, or writes into
/// a ring buffer with a fixed number of slots, or needs an account first. So
/// this endpoint is the whole of what an unauthenticated caller can add to the
/// database, and until now there was no ceiling on it: a loop could fill
/// AspNetUsers, and each request through it costs a deliberately expensive
/// password hash, so the cheaper attack is not the rows at all, it is one
/// container's CPU.</para>
///
/// <para>The security page argues that a rate limiter here would not be the
/// control that mattered, and the argument is about partitioning: behind the
/// edge the origin sees one address for every visitor, and because the origin
/// is directly reachable an attacker can bypass the edge and forge whatever
/// address they like, so a per-address limit is a global cap wearing a
/// disguise. That argument is correct and it says nothing about this, because
/// this limit does not partition by anything. There is nothing to forge.</para>
///
/// <para>What it costs is honest and worth stating: while somebody is spending
/// the hour's allowance, a real visitor cannot register either. That is the
/// trade, and it is the right way round for a demo. Browsing, signing in and
/// bidding all keep working, an existing account is untouched, and the ceiling
/// is set far above what this site has ever seen in a day, so the only person
/// who meets it is somebody trying to.</para>
/// </summary>
public sealed class RegistrationLimit(int perHour, Func<DateTimeOffset> now) : IAllowance
{
    /// <summary>
    /// Two an hour would be safer and would be a different product. This site
    /// has never seen more than a handful of registrations in a day, most of
    /// them its own tests, so a hundred and twenty leaves three orders of
    /// magnitude of headroom over real use and still bounds a day of abuse to
    /// something a serverless database does not notice.
    /// </summary>
    public const int DefaultPerHour = 120;

    private static readonly TimeSpan Window = TimeSpan.FromHours(1);

    /// <summary>
    /// When each of the last <see cref="PerHour"/> registrations happened,
    /// oldest first. A sliding window rather than a bucket that resets on the
    /// hour: a bucket lets an attacker take the whole allowance twice in two
    /// minutes by arriving either side of the reset.
    /// </summary>
    private readonly LinkedList<DateTimeOffset> _taken = new();

    private readonly Lock _gate = new();

    public int PerHour { get; } = perHour;

    /// <summary>
    /// Take one of the hour's registrations, or say there are none left. A
    /// refusal costs nothing and is not recorded: a caller who is turned away
    /// has not consumed anything, so a flood of refusals cannot extend the
    /// window it is being refused by.
    /// </summary>
    public bool TryTake()
    {
        DateTimeOffset moment = now();
        lock (_gate)
        {
            while (_taken.Count > 0 && moment - _taken.First!.Value >= Window)
            {
                _taken.RemoveFirst();
            }

            if (_taken.Count >= PerHour)
            {
                return false;
            }

            _taken.AddLast(moment);
            return true;
        }
    }

    /// <summary>
    /// Return the most recent slot, for a registration that was taken and then
    /// refused by Identity before any account existed: a weak password or an
    /// address already registered spends nothing, or a stranger could spend the
    /// hour's allowance with requests that were never going to make an account
    /// (ADR: The one write a stranger can make, addendum).
    /// </summary>
    public void GiveBack()
    {
        lock (_gate)
        {
            if (_taken.Count > 0)
            {
                _taken.RemoveLast();
            }
        }
    }
}

Live from api/TheYard.Api/Features/Accounts/RegistrationLimit.cs, region registration-limit, read from this build at 99df7a8.

Where it sits

The limit lives in the Api host: RegistrationLimit holds the sliding hour, and the register endpoint in Endpoints/AccountEndpoints.SignIn.cs calls TryTake after reading the request and GiveBack when Identity refuses the account. Single responsibility, one reason to change per class, fits here because the window logic sits in its own class and the endpoint only asks it for a slot. The cost is that a real visitor cannot register while somebody else spends the hour's 120 slots. The window also lives in one process's memory, so running a second instance, or adding the origin lock that a durable counter would need, is when this should move into a shared store.

Addendum, 2026-10-20 (1.0.3.188): the other store is refused, not skipped

Until 1.0.3.187 the stamp check passed a token whose store was not the request's store, on the argument that the endpoints refuse it. After 19 October one process serves both stores, and its own address is one origin for both, so a cookie issued on one store reaches the other with the header that picks it; a session ended on its own store still opened the other one with its old claims. From 1.0.3.188 the check is RefuseSession, handed the request's store and accounts by constructor, and it refuses a token from the other store before any endpoint runs. RefuseSessionTests holds the refusal with fake ports, and AuthTests signs out on one store and sends the dead cookie to both.

Files

Addendum, 2026-09-09: the second write a stranger could make, and the slot that leaked

Two things a review with no context found in this record's own territory, both fixed in 1.0.0.109. First, the proof (ADR: Same performance, proven) had a second anonymous write: POST /api/admin/proof started a run that registered two accounts and placed sixteen bids, and a loop of one start a minute, which its cooldown allowed, spent exactly this record's 120 registrations an hour, so a stranger could close registration by asking the site to measure itself. Starting a run takes a signed-in visitor now, and the proof's accounts are made once per process and reused, so the loop that remains costs nothing this record guards. Second, the slot was taken before Identity had its say: a request the limiter accepted and Identity then refused, a short password or an address already registered, kept its slot, so a stranger could spend the hour's allowance with requests that were never going to make an account. RegistrationLimit.GiveBack returns the slot on that path, and two tests hold it, one on the window and one through the endpoint. The rule this record stated stands, and is true again: one write a stranger can make, and only the ones that happen are counted.

Addendum, 2026-10-18: the list was not the whole list

The list above stopped being the whole list as the Admin tab grew, and a review on 2026-10-18 found three more things a stranger could cause. Two were routes: GET /api/admin/selftest/exception, which throws on purpose and lands in the server's error ring and the kept log on every call, so a loop of them pushed the operator's real errors off the page; and POST /api/admin/pages, which starts a sweep that dials every served address on the loopback. The third was a bid with no ceiling: int.MaxValue was accepted and the next minimum wrapped to a negative number on the wire.

From 1.0.3.169 both routes need a signed-in session, like the proof's start, and the self-test runs once a minute per account. A bid above BidRules.MaxBid, ten million dollars, is refused before any sum is made, and arithmetic in Domain is checked, so a price that would wrap throws instead. The operator's key is read from the X-Admin-Key header and never from the address, because an address is written into the request logs of App Service, Front Door and Application Insights. And a session can now be ended: each token carries a fingerprint of the account's security stamp, every request checks it against the account, and both a password change and a sign-out move the stamp, so a copied cookie stops working the moment its owner signs out or resets.

What a stranger can cause is the list above again: reads, the browser's error ring, and an account.

/// <summary>
/// Refuses a session that has ended: one opened on the other store, one whose account has moved
/// its security stamp since the token was issued (after a password reset, after a sign-out on
/// any device), or one whose account is gone. Read on every request that carries a valid token,
/// from the store the request is on, which is one point read; a token is a year long, and
/// without this nothing could end one early.
///
/// <para>The other store is refused, not skipped. One process serves both stores, and its own
/// address is one origin for both, so a cookie issued on one store reaches the other; were it
/// passed through, a session ended on its own store would still open the other one with its
/// old claims.</para>
/// </summary>
public sealed class RefuseSession(CurrentBackend current, RequestAccounts accounts)
{
    /// <summary>Why the token in <paramref name="principal"/> no longer opens a session, or null when it still does.</summary>
    /// <param name="principal">The claims the token carried.</param>
    /// <param name="cancellation">The request's cancellation.</param>
    public async Task<string?> HandleAsync(ClaimsPrincipal? principal, CancellationToken cancellation)
    {
        string? id = principal?.FindFirstValue(ClaimTypes.NameIdentifier);
        string? store = principal?.FindFirstValue(TokenIssuer.StoreClaim);
        string? stamp = principal?.FindFirstValue(TokenIssuer.StampClaim);
        if (id is null)
        {
            return "the session names no account";
        }
        if (!string.Equals(store, current.Backend.Key, StringComparison.Ordinal))
        {
            return "the session belongs to the other store";
        }
        // A store that did not come up has no accounts to compare with; every endpoint that needs
        // an account refuses on its own, because RequestAccounts answers null for it too.
        if (accounts.Users is not { } users)
        {
            return null;
        }

        cancellation.ThrowIfCancellationRequested();
        var user = await users.FindByIdAsync(id);
        if (user is null)
        {
            return "the account no longer exists";
        }
        return stamp is not null && string.Equals(stamp, TokenIssuer.Fingerprint(user.SecurityStamp), StringComparison.Ordinal)
            ? null
            : "the session was ended by a sign-out or a password change";
    }
}

/// <summary>
/// What the JWT reader does with a request, resolved from that request's services so the
/// refusal is handed its store and accounts by constructor: the token is read from a cookie, and
/// a valid signature is not enough until <see cref="RefuseSession"/> has said yes.
/// </summary>
public sealed class SessionEvents(RefuseSession refuse) : JwtBearerEvents
{
    /// <summary>The token arrives in a cookie rather than an Authorization header, because a page that can read its own token can leak it.</summary>
    /// <param name="context">The message being read.</param>
    public override Task MessageReceived(MessageReceivedContext context)
    {
        if (context.Request.Cookies.TryGetValue(TokenIssuer.CookieName, out string? cookie))
        {
            context.Token = cookie;
        }
        return Task.CompletedTask;
    }

    /// <summary>Fails a validated token whose session has ended, with the reason.</summary>
    /// <param name="context">The token that validated.</param>
    public override async Task TokenValidated(TokenValidatedContext context)
    {
        if (await refuse.HandleAsync(context.Principal, context.HttpContext.RequestAborted) is { } reason)
        {
            context.Fail(reason);
        }
    }
}

Live from api/TheYard.Api/Features/Accounts/RefuseSession.cs, region session-stamp, read from this build at 99df7a8.

Enforced by

Not machine-checked. Held by review.

Store

The Yard, home

Steven StoutStaff .NET engineerRemote

Production .NET that stays up. Built with AI, measured on every version.

Steven Stout

Hi, I'm Steve. I build the systems that make delivery boring in the best way, then coach people inside them.

  • 200+

    production releases, none took the platform down

    Conway Investment Research, 2019 to 2024. Sole engineer for the first three years on a live financial advisory platform.

    See how
  • 50%

    shorter release cycle

    Storee Construction, 2024 to 2026. Four ASP.NET applications onto one .NET 10 platform on Azure, with a four-person team I hired and mentored.

    See how

01Verified

Steven Stout

A real person, and the work is mine.

  • Identity

    Checked by LinkedIn, not by me.

    LinkedIn verified my government ID.

  • Running system

    You are looking at it.

    Version 1.0.5.273 is live. Nothing ships unless it passes the automated gates first.

That's who I am. Here's how I work.

02Strengths

Ten strengths, each with the proof beside it. The numbers match my resume and LinkedIn, and the live ones are read from this site as you look.

  • 01

    Keeps production alive

    200+ releases on a live financial platform, and none took it down. Sole engineer for the first three years.

    See the Conway work

  • 02

    Simplifies messy systems

    Four ASP.NET applications onto one .NET 10 platform on Azure, and a release cycle 50% shorter.

    See the Storee work

  • 03

    Marries dev and infrastructure

    Blue-green releases at Storee that flipped in about 5 seconds with nobody signed out, and Azure Front Door at two employers.

    See this site's cloud

  • 04

    Designs data that holds up

    White-label clients on one shared database, the isolation built into the data, and no cross-client issues.

    See the Conway work

  • 05

    Keeps AI-written code honest

    15 quality numbers that may only improve: 273 releases in a row with none worse.

    See the quality numbers

  • 06

    Resourceful

    $30,000+ cut from Azure and vendor spend at Conway. This site's Azure bill is public, resource by resource.

    See the bill

  • 07

    Builds people up

    Hired and mentored a four-person team. 13 colleagues recommend me by name.

    Read the recommendations

  • 08

    Takes ideas to production

    This site: designed, built and run solo, with 352 versions measured through one gate.

    How it was built

  • 09

    Writes clearly

    Posts on real engineering problems, in plain words.

    Read the blog

  • 10

    Owns decisions

    153 decision records, each with its tradeoff and the call I made.

    See the decision records

Built with AI. Gated so quality never slides.

Steven Stout’s showcase: a used-vehicle auction on .NET and React, built and run by one engineer, live on Azure, with its decisions written down.

No quality number has gotten worse at any release since 1.0.5.1 on 10 November: 273 releases in a row.

One engineer, an AI agent and a gate that checks 15 quality numbers on every release. 352 versions measured, with every result public, the worst days included.

82 releases in the last 7 days, each through the same gate.

Async methods with no CancellationToken, may only fall

11091.0.3.1391.0.5.2731.0.4.115, the ratchet
Every number, on the Quality page

TheYard, right nowLive

Answering in

unread

02505007501,000

server time at p95, the usual five minutes of the last day.

Azure this month

unread

the bill, by resource, read from Azure. The Admin tab shows every line.

Since the last roll

unread

 

rolled in place by the pipeline, behind one gate.

People who have visited

unread

30 days agotoday

Scanners, my own tools' and my own reads left out.

03Start here

04Where teams are heading

How I see engineering with AI, and the setup on this site that backs it.

AI-augmented teams · Architecture and ownership

AI writes more of the code. Someone still has to own what ships.

Teams are going to be heavily AI-augmented. That moves the senior job toward architecture and technical ownership: deciding what to build in pieces small enough to verify, and owning what ships.

  • Task tracking will get automated too. Judgment stays human: seeing a design fail at scale before it does.
  • On this site the AI's first design held the whole catalogue in memory. I caught it when the App Service plan hit 82 per cent and moved the work to the store.

What the AI wrote, what I decided

07Tech stack

  •    
  •    
  •    

Read from the build, never typed by hand

What TheYard runs on

What we use, where it runs, its AWS twin, the version as built, and the file that proves it.

Cloud patterns, not one vendor: every Azure piece in this stack has a named AWS twin. Mapped, not yet run on AWS.

  • .NET 1114 projects
  • React 19.3TypeScript 7.0
  • Azure9 Bicep files
  • 11GitHub Actions workflows
The whole stack, with the file that proves each line

The last release the gate stopped was 1.0.5.258 on 2 December, at its browser 1 of 2 job.

08How it is built

09How it is run

10Who and why

Next step

11What has to work, where is it today, and what does success look like?

Book 20 minutes opens an email to me with those three questions in it, and I answer with a time.

Book 20 minutes

Your email app should have opened with this message. If it did not, copy it and send it from any mailbox.

Or message me on LinkedIn