Dev.to Security 🔐 Cybersecurity 👁 0 📖 5 min read

Near miss: the bill-paying agent that would have read "I can't see the ledger" as "nothing paid today"

Our Near Miss entry for Agentware 2026 by Hackathon Raptors (@raptorsdev). The build: Payables Sentinel, an unattended agent that reads bills from an inbox, pays the ones you'd pay anyway, and holds the ones a fraudster

Our Near Miss entry for Agentware 2026 by Hackathon Raptors (@raptorsdev). The build: Payables Sentinel, an unattended agent that reads bills from an inbox, pays the ones you'd pay anyway, and holds the ones a fraudster wrote.

The guardrail that looked done

Payables Sentinel has a daily spending cap: £300 a day, £150 per payment. Before it pays anything, the policy asks the bank's own ledger two questions: how much has gone out today, and has this exact bill been paid before. That second question is the duplicate check. A re-sent invoice gets the same key and is refused.

Four and a half hours into the 72-hour window, this is the line that fed both checks:

const ledger = await bank.list().catch(() => [] as any[]);

It reads as defensive code. It's the opposite. If the ledger call failed (a timeout, a 500, a flaky network), ledger became an empty list. The policy then saw "paid today: £0.00" and "no earlier payments", and both checks passed on information the agent did not have.

What could have happened: run it yourself

The failure needs a partial outage: the ledger read fails, but the payment call still works. So we wrote a repro that puts a small proxy in front of the demo bank and fails only GET /payments (repro.mts + repro.sh, it runs the repo's own processFile and bank, and it lives outside the repo because the code is frozen). Four ordinary bills from vendors on file: council tax £142.00, electricity £89.46 and water £41.20 while the ledger works, then the ledger read starts failing and the broadband bill arrives (£32.00).

bash repro.sh 7329b82 runs the commit just before the fix:

a-council.eml: PAY
b-electricity.eml: PAY
c-water.eml: PAY
-- the ledger read starts failing (payments still work) --
d-broadband.eml: PAY
bank: 4 payments today, total £304.66 (daily cap £300.00) -> CAP CROSSED

bash repro.sh 83181cc runs the frozen code:

d-broadband.eml: HOLD  [P05b: the bank's ledger could not be read (bank unavailable after 4 tries (HTTP 503: ledger temporarily unavailable)): daily cap and duplicates can't be checked]
bank: 3 payments today, total £272.66 (daily cap £300.00) -> cap held

The overrun here is small (£4.66), because ordinary bills are small. The point is that it had no limit: with the ledger unreadable, every further bill of the day started from £0.00. Nobody asked the agent to raise its own limit. A swallowed error did that. It never happened in a real run, and the bank's idempotency key would still have stopped an exact double payment. But the daily cap, the one limit an owner sets so they can sleep, rested on a read that could fail silently.

How we found it: our own test said it was fine

We had a test called "bank down for good: the item is held, nothing paid". It passed. Reading it again late on 27 Nov, we saw what it actually asserted:

assert.equal(d.action, "pay");   // the policy allowed it ...
assert.ok(...includes("failed safely"));   // ... the tool failed closed

The policy had said pay. The test only passed because the bank was down for every call, so the payment call failed too. The test protected the outcome by luck, and it wrote the wrong belief into the suite. In a partial outage, where only the ledger read fails, nothing would have stopped the payment.

The fix (commit dbbc864, 27 Nov 22:35 UTC)

An unreadable ledger is now its own rule, P05b, and it holds the bill:

let ledger: any[] = [], ledgerError: string | null = null;
try { ledger = await bank.list(); }
catch (e) { ledgerError = (e as Error).message; /* logged to the trace as a bank.list error */ }
...
if (c.ledgerError) add("P05b", false,
  `the bank's ledger could not be read (${c.ledgerError}): daily cap and duplicates can't be checked`);

In the repro run of the frozen code, the hash-chained trace records the failed read and the hold:

trace #30 tool bank.list: {"error":"bank unavailable after 4 tries (HTTP 503: ledger temporarily unavailable)"}
trace #32 held approval.request: {"file":"held/d-broadband.eml.json","reasons":["P05b: the bank's ledger could not be read (bank unavailable after 4 tries (HTTP 503: ledger temporarily unavailable)): daily cap and duplicates can't be checked"]}

and held/INDEX.md gets one line for the owner:

- d-broadband.eml: P05b: the bank's ledger could not be read (bank unavailable after 4 tries (HTTP 503: ledger temporarily unavailable)): daily cap and duplicates can't be checked

P05b is on the list of rules an owner cannot approve past. A human can approve an over-cap bill they recognise, but nobody can approve "we don't know what was paid today". The bill waits in held/ with the reason written out, and nothing moves until the ledger can be read again.

We rewrote the old test to assert the policy itself says hold with P05b failing. We also added a second test for the opposite case: the ledger read works and only the schedule call fails. There the tool fails closed and the bill is held, so both halves now have their own test. The commit changes 6 files, and the suite went to 40 tests (47 by the code freeze).

What we took from it

  • .catch(() => []) on a safety input turns "unknown" into "zero". For anything a limit is computed from, a failed read is a reason to stop, not a default value.
  • A test can pass for the wrong reason. Ours checked the end state (nothing paid) when it should have checked the decision (hold). Assert the decision that is supposed to protect you.
  • "Can't check" is not something a human should approve past. Some rules are about the bill. This one is about whether the agent can see at all.

The same review turned up a second near miss about two and a half hours later, in the same session: a kill switch that could leave behind a payment whose bank call was still in flight. Same lesson: record what you are about to do before the side effect starts, not after it returns. That one is fixed too, in 83181cc (tested as "kill while the payment call itself is pending").

Built for Agentware 2026. Its Near Miss awards are backed by FileClerk (fileclerk.co.uk), and it's good to see a sponsor that pays for honest write-ups about what nearly went wrong. #HackathonRaptors

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.