The database, not the code, refuses the overspend.
Try to break it
The button connects as stub_app, the same least-privilege role the app runs as, and sends the six statements below. Each runs inside its own BEGIN and ROLLBACK, so nothing persists. The codes come straight from the database.
- 1Drive a budget balance below zero
UPDATE accounts SET balance_micro = -1 WHERE id = (SELECT id FROM accounts WHERE type = 'agent' ORDER BY id LIMIT 1)expects 23514 - 2Raise a budget above its cap
UPDATE accounts SET balance_micro = cap_micro + 1 WHERE id = (SELECT id FROM accounts WHERE type = 'agent' AND cap_micro IS NOT NULL ORDER BY id LIMIT 1)expects 23514 - 3Rewrite a ledger entry
UPDATE entries SET amount_micro = 0 WHERE id = (SELECT id FROM entries ORDER BY id LIMIT 1)expects 42501 - 4Delete a ledger entry
DELETE FROM entries WHERE id = (SELECT id FROM entries ORDER BY id LIMIT 1)expects 42501 - 5Create a table
CREATE TABLE stub_proof_probe (id INT PRIMARY KEY)expects 42501 - 6Drop the entries table
DROP TABLE entriesexpects 42501
Ten writers, one $3.00 budget
Each writer spends $1.00 with a raw UPDATE that skips the app's check, the way a script or a hotfix would. On the old schema the same ten writes took a $3.00 budget to -$7.00 in every run (20 of 20 runs, $140.00 accepted that was not there). Now the database refuses seven of them with 23514, and the balance stops at $0.00 in all 20 runs.
- Before: no CHECK, 10 of 10 committed
- After: CHECK validated, 3 committed, 7 refused
- Refused write, balance unchanged
Show the numbers
| Write | Before | After |
|---|---|---|
| Start | $3.00 budget | $3.00 budget |
| 1 | $2.00, committed | $2.00, committed |
| 2 | $1.00, committed | $1.00, committed |
| 3 | $0.00, committed | $0.00, committed |
| 4 | -$1.00, committed | $0.00, refused 23514 |
| 5 | -$2.00, committed | $0.00, refused 23514 |
| 6 | -$3.00, committed | $0.00, refused 23514 |
| 7 | -$4.00, committed | $0.00, refused 23514 |
| 8 | -$5.00, committed | $0.00, refused 23514 |
| 9 | -$6.00, committed | $0.00, refused 23514 |
| 10 | -$7.00, committed | $0.00, refused 23514 |
These checks came out of an AWS Well-Architected review. Every before and after number, from the database role to backups and Region failover, is on the security review page.
Read the security reviewReproduce it yourself
The guardrail tests run offline, with no database. Against Aurora DSQL, map an IAM role to the app's database role and run the probe script, which prints the SQLSTATE for each statement it sends. On local Postgres, the local test suite sends the six statements above as stub_app, and CI runs it on every push to main and every pull request.
npm test
npm run migrate && npm run db:app-role
npm run db:app-role -- grant <iam-role-arn>
DSQL_USER=stub_app npx tsx scripts/wa-probe.ts