Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[codespell]
builtin = clear,rare,en-GB_to_en-US
skip = *.pdf,*.png,*.jpg,*.jpeg,*.gif,*.csv,*.tsv,*.json,*.geojson,*.graphml,*.ipynb,*.html,*.svg,*.bib,*.bbl,*.lock,*.parquet,*.rda,*.rds,*.RData,*.dta,*.xlsx,*.xml,*.min.js,*.map,*.log,*.aux
ignore-words-list = afterall,authorisation,authorised,defence,enrol,enrolment,honours,normalise,requestor,unauthorised
18 changes: 18 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: codespell

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: codespell-project/actions-codespell@e3258cca84ce02b0bb36a3d41f2c18f719a0cc1a # v2.4.3
62 changes: 31 additions & 31 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Include what you did, what happened, and what you expected. A failing test again

This repository is the **R0 demonstrator**. All accounts, balances and payments are simulated fixtures;
no real financial data exists anywhere in it and no money can move. Findings are still in scope,
because the same authorisation, approval and dispatch code will carry real data in later releases.
because the same authorization, approval and dispatch code will carry real data in later releases.

Especially wanted:

Expand Down
8 changes: 4 additions & 4 deletions docs/THREAT_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ legitimate grant; they often have physical access to the owner's device, and soc

| Attack | Control | Evidence |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| See unshared accounts or totals | One authorisation rule; lists and totals are built from visible resources only | `access-property.test.ts`, `grants.test.ts` "scopes reads…" |
| See unshared accounts or totals | One authorization rule; lists and totals are built from visible resources only | `access-property.test.ts`, `grants.test.ts` "scopes reads…" |
| Guess another account's ID | Unauthorised and nonexistent both return 404 | `grants.test.ts`, `api.test.ts` "404 parity" |
| Widen their own grant | Only the grantor can set a grant, and only with their own passkey over the exact grant | `grants.test.ts` "never lets a delegate widen…" |
| Approve a payment themselves | Approval requires actor = owner plus the owner's passkey over the revision digest | `payment-flow.test.ts` "lets only the owner approve" |
| Get approval for one amount, then change it | Every change creates a new revision; approval is bound to the digest | `payment-flow.test.ts` "invalidates approval…" |
| Split one payment into many under a limit | Monthly limit, reserved atomically, and pending payments count | `races.test.ts` "concurrent payments…" |
| Keep acting after being revoked | Revocation cancels unsent payments at commit; the gate re-checks the grant under lock | `races.test.ts`, `controls.test.ts` "revocation cancels…" |
| **Add their own passkey to the owner's account while holding the owner's device or session** | Enrolment requires step-up with an existing passkey (hardening #1) | `security.test.ts` "passkey enrolment…" |
| **Add their own passkey to the owner's account while holding the owner's device or session** | Enrolment requires step-up with an existing passkey (hardening #1) | `security.test.ts` "passkey enrollment…" |
| **Act without the owner knowing** | Out-of-band notices to the owner and a trusted contact (hardening #2) | `security.test.ts` "notifies…" |
| Start recovery to take over the owner's account | Only the owner or support can start it; recovery freezes execution and revokes sessions | `controls.test.ts` "recovery…", `security.test.ts` "recovery revokes sessions" |
| Pressure the owner into approving | **Residual risk.** Notices to a trusted contact are the only technical control. There is deliberately no cooling-off period (product decision, 2026-09-28). | — |
Expand All @@ -55,7 +55,7 @@ with a new "helper" or approving a payment, often in real time on the phone.
| Attack | Control | Evidence |
| ---------------------------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
| Steal a session cookie | `__Host-` cookie, HttpOnly, Secure, SameSite=strict; tokens stored as hashes; idle and absolute expiry | `security.test.ts` "sessions…" |
| Use a stolen session to move money | Money and authority always need a passkey; a session alone can do neither, including enrolling a passkey | `security.test.ts` "passkey enrolment…" |
| Use a stolen session to move money | Money and authority always need a passkey; a session alone can do neither, including enrolling a passkey | `security.test.ts` "passkey enrollment…" |
| CSRF | SameSite=strict, plus an `Origin` / `Sec-Fetch-Site` check on every mutation | `security.test.ts` "rejects cross-site mutations" |
| XSS | React escaping; strict CSP with no inline scripts; fonts self-hosted | `security.test.ts` "security headers" |
| Brute force or enumeration | Rate limits on login, step-up and webhooks | `security.test.ts` "rate limits" |
Expand Down Expand Up @@ -115,7 +115,7 @@ The reviewer also suspected three things, now addressed:

- **Unsolicited access requests with free-text notes, a scammer's lure.** Only existing delegates can ask for more.
- **Trusted-contact independence could be dodged with plus-addressing.** Addresses are compared case-insensitively and without `+tags`.
- **Support could open an enrolment window by freezing an account with the right reason text.** Recovery is now a state of its own.
- **Support could open an enrollment window by freezing an account with the right reason text.** Recovery is now a state of its own.

## Out of scope for R0

Expand Down
2 changes: 1 addition & 1 deletion src/db/migrations/0004_recovery_state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Kysely, sql } from "kysely";

// Recovery is a state of its own, not a freeze reason typed as free text, so
// support can't open an enrolment window by freezing with the right words.
// support can't open an enrollment window by freezing with the right words.
export async function up(db: Kysely<unknown>): Promise<void> {
await sql`alter table person add column recovery_started_at timestamptz`.execute(db);
}
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sql } from "kysely";
import type { Executor } from "../db/index.js";
import { KernelError, type Registry } from "./registry.js";

// Authorisation is plain SQL over grants rather than a policy engine. The
// Authorization is plain SQL over grants rather than a policy engine. The
// rules that matter here are stateful (grant versions, row locks against
// revocation, spending reservations), which a stateless engine such as Cedar
// cannot enforce, so it would add a second system without removing any code.
Expand Down Expand Up @@ -75,7 +75,7 @@ export async function canAccess(
return g !== undefined;
}

// Unauthorised and nonexistent look identical, so a guessed ID reveals nothing.
// Unauthorized and nonexistent look identical, so a guessed ID reveals nothing.
export async function requireAccess(
ex: Executor,
registry: Registry,
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface AuditRecord {
}

const GENESIS = "sha256:genesis";
// Arbitrary constant; serialises audit appends so each row can chain to the previous hash.
// Arbitrary constant; serializes audit appends so each row can chain to the previous hash.
const AUDIT_LOCK = 7_331_001;

function hashBody(r: Omit<AuditRecord, "seq" | "hash">): string {
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/canonical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
import canonicalize from "canonicalize";

// RFC 8785 (JSON Canonicalization Scheme): the same logical object always
// serialises to the same bytes, so a digest identifies the exact content.
// serializes to the same bytes, so a digest identifies the exact content.
export function canonicalJson(value: unknown): string {
const out = canonicalize(value);
if (out === undefined) throw new Error("value cannot be canonicalised");
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function unfreezeOwner(k: Kernel, ownerId: string, stepUpResponse:

// Recovery (lost passkey). The owner's old credentials are removed and all
// execution is frozen until the owner completes independent verification and
// enrols a new passkey. A delegate can neither start nor finish this: the
// enrolls a new passkey. A delegate can neither start nor finish this: the
// actor must be the owner (in R0 the independent verification is simulated).
export async function startRecovery(k: Kernel, actorId: string, ownerId: string) {
if (actorId !== ownerId && !(await isSupport(k.db, actorId))) {
Expand Down Expand Up @@ -137,7 +137,7 @@ const ENROLMENT_WINDOW_MS = 60 * 60 * 1000;

// Independent identity verification. In R0 a support agent attests to it; in
// R1 this is an identity-verification provider. It opens a one-hour window in
// which the owner, and only the owner, can enrol a new first passkey.
// which the owner, and only the owner, can enroll a new first passkey.
export async function completeRecoveryVerification(k: Kernel, actorId: string, ownerId: string) {
await requireSupport(k, actorId);
await k.db.transaction().execute(async (tx) => {
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ async function hold(tx: Tx, intentId: string, status: string, why: string): Prom
return { kind: "held", why };
}

// Every check that authorised this intent is repeated here, inside one
// Every check that authorized this intent is repeated here, inside one
// transaction that holds a lock on the intent and a share lock on the
// delegate's grant. Revocation takes an update lock on the same grant row, so
// the two serialise: if revocation commits first, this sees it and nothing is
// the two serialize: if revocation commits first, this sees it and nothing is
// sent; if this commits first, the intent is already Dispatching and
// revocation can only request cancellation (P7, PRD §10).
//
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface IntentExecutor<D> {
lookup(idempotencyKey: string): Promise<LookupResult>;
getOperation(operationId: string): Promise<LookupResult>;
cancel(operationId: string): Promise<{ canceled: boolean; reason: string }>;
// Maps a provider status to a normalised intent status or "Failed".
// Maps a provider status to a normalized intent status or "Failed".
normalize(rawStatus: string): string;
verifyWebhook(headers: Record<string, string | undefined>, body: string): ProviderEvent | null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/stepup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { KernelError } from "./registry.js";
// Step-up authentication for anything that expands authority or moves money:
// creating or widening a grant, approving an intent, finishing recovery. Each
// challenge is bound to a purpose and to the digest of the exact thing being
// authorised, and is single-use. A link in an email or a notification only
// authorized, and is single-use. A link in an email or a notification only
// opens the screen; it can never supply this proof.

export type StepUpPurpose = "grant" | "approve" | "register" | "recovery" | "enrol";
Expand Down
4 changes: 2 additions & 2 deletions src/modules/finance/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export async function paymentCapability(
};
}
const days = (Date.parse(d.scheduledDate) - Date.parse(todayUtc())) / 86_400_000;
// Owners' time zones are not modelled yet; allowing yesterday-in-UTC accepts
// Owners' time zones are not modeled yet; allowing yesterday-in-UTC accepts
// "today" anywhere in the Americas. Dispatch never happens before now anyway.
if (days < -1) return { state: "unavailable", reason: "The scheduled date is in the past." };
if (days > MAX_DAYS_AHEAD)
Expand Down Expand Up @@ -241,7 +241,7 @@ function periodKey(tz: string, at = new Date()): string {
}

// Cumulative caps are reserved atomically: an advisory lock per grant
// serialises concurrent dispatches, pending payments count, and only a
// serializes concurrent dispatches, pending payments count, and only a
// definitive failure or return gives the capacity back (PRD §7).
async function reserve(
tx: Tx,
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (existing.length) {
process.exit(0);
}

// Simulated account creation: each person may enrol a first passkey for 30 days.
// Simulated account creation: each person may enroll a first passkey for 30 days.
const window = new Date(Date.now() + 30 * 86_400_000);
await k.db
.insertInto("person")
Expand Down
2 changes: 1 addition & 1 deletion test/access-property.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { addPayee, selectAccounts } from "../src/modules/finance/connections.js"
import { accountsView } from "../src/modules/finance/reads.js";
import { connectAll, freshApp, grant, type TestApp, resume } from "./helpers.js";

// The SQL authorisation is checked against an in-memory model that shares no
// The SQL authorization is checked against an in-memory model that shares no
// code with it: random sequences of grant, pause, resume, revoke and deselect,
// then every (person, scope, resource) triple is compared.

Expand Down
2 changes: 1 addition & 1 deletion test/redteam.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
status,
} from "./scenarios/setup.js";

// Red-team tests. Each asserts the SECURE behaviour, so each fails while the
// Red-team tests. Each asserts the SECURE behavior, so each fails while the
// weakness it names exists. Adversary labels follow docs/THREAT_MODEL.md.

const rp = { id: "localhost", name: "test", origin: "http://localhost:5173" };
Expand Down
Loading