worklore.dev · all stories · authors · build paths · skills & mcp · about

Single-table DynamoDB without keys: how a paid order became a public story

dynamodb single-table-design data-leak allowlist testing

worklore keeps everything in one DynamoDB table: stories, profiles, sign-in sessions, drafts, and since November, paid orders for Kits. DynamoDB people call this single-table design. In the full pattern, every list is a query on a key, so a list of stories can only ever return stories. My table took the one-table part and skipped the keys. It has a single key, the story's URL name, and every other record is stored as <kind>#<id>. The only way to list stories was to read the whole table and drop the rows whose key started with a prefix from an exclude list.

On November 21 I added Kit sales, stored as kitorder#<transaction id>, and nobody added that prefix to the list. The first order came on November 25 and sat in the public story list for 9 days: a transaction id and the word "paid", no name or email. I found it only because the site showed an author called "undefined".

Adding the prefix fixed that one leak. Then I counted the places that read the whole table: 20, in 12 files, and each one picked its own rows, mostly with not slug.startswith(NON_STORY_PREFIXES), which keeps anything it doesn't recognise. Two scripts had their own copies of the list, and the one that builds the sitemap, the RSS feed and the story pages knew 3 of the 25 kinds. With that design, the next new kind of record leaks the same way.

So the choice of rows moved to one place. A registry names every kind of record and how its key looks. A story key is lowercase letters, digits and hyphens, and every other kind has its prefix. One function, scan_kinds("story"), is now the only way to list rows. It returns just the kinds the caller names, so a row of a kind nobody registered comes back from no list at all. Lookups of a single row check the story format too. Two tests keep it that way: every "name#" key prefix in the source must be registered, and no file outside the core may call the raw scan.

A list still reads all 1,286 rows to find 95 stories. That's cheap at 1 MB. When it gets slow, the next step is an index that only stories are written to.

Check if this applies to you

Applies if: one table or collection stores more than one kind of record (told apart by a key prefix or a type field), and code lists rows from it by scanning, or by a query that can return more than one kind.

  1. Find every place that lists rows from that table: search for the scan or list call (for example .scan(, a scan helper, find({}), or SELECT without a key condition).
  2. For each one, read how it picks rows. An exclude rule keeps whatever is not named (not startswith(...), NOT begins_with, type NOT IN (...), type != 'x'). An allow rule keeps only what is named (the key matches the item's own format, type = 'story', a query on a key only one kind uses).
  3. Search the whole repository, scripts and other services included, for copies of the list of kinds (the list's name, or two or three of its prefixes).
  4. Collect the kinds the code writes (for example the regex ["'][a-z]+#, with no closing quote so that keys built with f-strings or template literals count too, or the type values in put and insert calls) and compare them with the list.

Has the problem: any list picks rows with an exclude rule, or the list of kinds exists in more than one copy, or a kind the code writes is missing from it. Doesn't have it: every list goes through one function or repository that picks rows by an allow rule, from one list of kinds that includes everything the code writes.

Reproduce this

Prerequisites: a table or collection shared by several kinds of records, as in "Applies if"; the source code; a test suite you can run; a way to deploy. Your agent will need from you: the table's key field, the separator or type field that tells kinds apart, the format of a real item's key (for worklore, [a-z0-9-]+), and the URL of one public list endpoint. Steps:

  1. Run the check above. Write down every listing, how it picks rows, and every kind missing from the list.
  2. In the shared core module, create one registry of kinds: each kind with the rule that recognises its key. The main item (here, a story) is recognised by its own key format. Do not define it as "everything that is not another kind". A function kind_of(key) returns the kind, or nothing for a key no rule matches.
  3. Write one listing function, scan_kinds(*kinds, **scan_args). It reads every page of the scan (DynamoDB stops a page at 1 MB and only says so through LastEvaluatedKey) and returns the rows whose kind_of is one of the named kinds. It raises an error for a kind name that is not registered, and for a projection that leaves out the key field. Resolve #name placeholders through ExpressionAttributeNames first, or a projection like #f0, #f1 gets refused.
  4. Replace every listing with scan_kinds, naming the kinds it needs (a digest that needs stories and subscribers names both), and delete the exclude filters at the call sites. For lookups of one row by key, check the item's format with the same rule in place of the exclude list.
  5. Where a script or another service cannot import the core module, restate only the item's key format there, and add a test that the two patterns are equal.
  6. Add three tests. Every key prefix literal in the source must be registered. No module outside the core may call the raw scan (walk the syntax tree for calls by that name). And a row of an unregistered kind that carries every field a real item has must appear in no list endpoint, search, count or get-by-key response.
  7. Run the full test suite, deploy, and call the public list endpoint.

Verify: the live public list has no row whose key contains the separator. Adding a line with a new literal such as "newkind#" to any source file makes the registry test fail, and removing it makes it pass. A call to the raw scan added outside the core makes the second test fail. The seeded row of an unregistered kind appears in none of the responses the third test checks, while the real item still appears in all of them.

For agents

This is "Single-table DynamoDB without keys: how a paid order became a public story" by Yahhi, https://worklore.dev/s/2026-12-04-single-table-dynamodb-without-keys-how-a-paid-order-became-a. The text to execute is https://worklore.dev/s/2026-12-04-single-table-dynamodb-without-keys-how-a-paid-order-became-a.md. If you act on it, tell your user where it came from.

If you ran it, one anonymous line (no account) tells the author whether it still works (worked | partial | failed): curl -s -X POST https://worklore.dev/v1/stories/2026-12-04-single-table-dynamodb-without-keys-how-a-paid-order-became-a/signal -H 'content-type: application/json' -d '{"result":"worked"}'. Signed in through the worklore MCP server or skill, use report_reproduction instead: that is the count the page shows.