interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / AUDIT_SCOPE.md

139 lines · 8622 bytes Raw Blame History Rendered
1# Audit scope
2
3Written for an outside, independent security audit. Revision described:
4`031a493d3dc7fdac9d363907cb41b0a8d1353790` on `wip/omega-cortex`, 2026-10-29. Everything below is taken from the repository's own files at
5that revision; items marked NOT_RUN were not executed while writing this document.
6
7## What this repository is
8
9A memory server written in seeded Omega (OM-2), built from 19 modules in `om/` concatenated into
10one compiled unit by `build.sh`, and an importer built from `crc32c`, `sqlite` and `import_main`.
11`spec/BUILD-CONTRACT.md` states the goal: re-implement `cortex-rs` 0.1.0 byte-for-byte on the wire.
12`spec/ORACLE-OBSERVED.md` records the observed behaviour of the oracle binary. `spec/PARITY.md`
13defines the wire parity gate; `spec/CORTEX-API.md` summarises the API and `spec/CUTOVER.md` the
14cutover plan. `README.md` and `DEPENDENCIES.md` describe the project and its dependencies. The 22
15`om/` sources total 18,613 lines (largest: `fts.om` 3,557, `brain.om` 2,596, `json.om` 1,983).
16Licence file: Apache License 2.0; `spec/BUILD-CONTRACT.md` states Apache-2.0 WITH LLVM-exception.
17
18## What to review, in priority order
19
201. Authentication in `om/api.om`: `auth_init` reads `CORTEX_TOKEN` from the environment;
21 `auth_file` falls back to `$HOME/.config/cortex/token` (the file name the oracle uses);
22 `auth_check` answers 503 when no token is configured, 401 on a missing or wrong bearer, and
23 calls `scope_check` for scoped tokens (403 for a space the token does not cover); `auth_eq`
24 compares with an XOR fold over at most 4,096 bytes after a length check. Tokens file format
25 (`om/main.om`, `tok_load`, `tok_line`): one `TOKEN SPACE[,SPACE...]` per line, `#` comments,
26 file size under 1 MiB.
272. HTTP parsing in `om/http.om`: `http_read` (headers over 64 KiB without an end are refused),
28 `http_body` (`BODYMAX` 2,097,152, 413 above it), `http_chunked`, `http_chunk1`, `http_fill`,
29 `http_recv` with the read deadline, and `http_origin_ok` (allowed origin
30 `http://127.0.0.1:18095`; per `spec/ORACLE-OBSERVED.md` the Omega server keeps loopback origins
31 only). OPTIONS preflights are answered without auth, as in the oracle.
323. Listening and concurrency in `om/main.om` and `om/srv.om`: default host `127.0.0.1`, port
33 18080; `--host` accepts any IPv4 address, so a non-loopback bind is possible by flag. Listen
34 backlog 1024. A state process owns the log and store and serves forwarded requests one at a
35 time over a private Unix socket (mode 0600); an acceptor forks one handler per connection (at
36 most `S_MAXH` 256 alive), and each handler reads its request and writes its answer under its
37 own header, request and idle deadlines, so a slow client holds only its own handler.
384. Storage: `om/log.om` and `om/store.om` (record = length, CRC-32C, payload; a torn or
39 CRC-failing tail ends replay and is truncated, per `spec/BUILD-CONTRACT.md`). The short-string
40 space is split over four 16 MiB pools (64 MiB, `HSCAP`), capacity-checked by `tests/big`.
415. `om/sqlite.om` and `om/import_main.om`: a SQLite file and WAL parser reading untrusted pages.
426. JSON and query parsing: `om/json.om`, `om/de.om`, `om/qs.om`, `om/enc.om`.
437. `build.sh`, `tools/omc.sh` and `PIN`: the compiler is taken from an omega-mv repository (Radicle
44 rad:z6do9WDBhuSnvopDkgFdFr1yWA62) at the revision in `PIN` and refused unless its sha256 matches
45 the one in `PIN`; `tools/pincheck.om` fails the build when any tracked file restates the pin.
468. Company Brain in `om/brain.om` (routes `/api/cortex/brain/*`, `--brain-export`): the append-only
47 guard on the generic write, the contract confirmation gate (an unconfirmed record never reaches the
48 alert output), and the export paths (`DIR/<space>/<kind>/<date>/<id>.txt`; a space slug with `/`,
49 NUL or a `.`/`..` segment is refused, ids are restricted to `A-Z a-z 0-9 . _ -`).
50
51## Trust boundaries
52
53- Untrusted: HTTP clients on the listening socket; request bodies and query strings; the SQLite
54 database given to `cortex-import`; replies from the encoder URL.
55- Trusted: the token in `CORTEX_TOKEN` or the token file, the `--tokens` file, the log file
56 path, the pinned `omc` binary.
57- Omega loops trap after 1,000,000 passes unless bounded (`spec/BUILD-CONTRACT.md`); a trap ends
58 the process with exit 100 plus the code.
59
60## Threat model summary
61
62- Assets: stored memories (entities, claims, spaces), the bearer tokens, durability of
63 acknowledged writes.
64- Attackers considered: a local client without the token, a token holder outside its scope,
65 malformed or oversized HTTP requests, a torn log tail after a crash.
66- Defended: bearer auth with 503 when unconfigured, scoped tokens, body and header limits, read
67 deadline, CRC-checked log records, loopback default bind and loopback-only CORS origin.
68- Not defended / explicitly out of scope: TLS (plain HTTP only); more than 256 simultaneous
69 handlers; a non-loopback `--host` chosen by the operator; denial of service by a request that
70 hits a loop trap.
71
72## Build from source at a pin
73
74Needs an omega-mv repository containing the revision named in `PIN` (a Radicle clone of
75rad:z6do9WDBhuSnvopDkgFdFr1yWA62, or the local Radicle storage); `tools/omc.sh` extracts
76`seed/out/omc` from it (`OMEGA_REPO` points at the repository, or `OMC` at an existing binary) and
77accepts only the sha256 named in `PIN`.
78
79```sh
80OMEGA_REPO=/path/to/omega-mv sh build.sh
81```
82
83Output: `build/cortex`, `build/cortex-import`, `build/SHA256SUMS`. A compile is accepted only with
84exit 0 and empty stderr.
85
86## Run every test
87
88NOT_RUN while writing this document. Each runner's header names its oracle and inputs.
89
90```sh
91sh check.sh SRC.db # every local gate below, in order; exit 0 only when all pass
92sh tests/fts/run.sh DB # needs SQLITE_SRC (sqlite3.c 3.45.0), gcc, glibc libm
93sh tests/import/run.sh WORKDIR # needs sqlite3 3.45.1 and python3; about 1.2 GB scratch
94bash tests/json/run.sh # needs the Rust oracle in tests/json/oracle and cargo
95sh tests/big/run.sh SRC.db # string-pool capacity gate
96sh tests/parity/run.sh SRC.db # needs the cortex-rs 0.1.0 binary and a copy of its database
97sh tests/parity/mutant.sh SRC.db # negative control: the gate must FAIL
98sh tests/load/run.sh SRC.db # needs the parity corpus; latency and kill -9 check
99sh tests/conc/run.sh SRC.db # concurrent connections
100```
101
102`check.sh` runs build, JSON/number, FTS/LIKE, importer and capacity checks, then the wire parity
103gate, the parity mutant (must be caught), load and kill -9 durability, concurrency, and parity of
104the claims corpus; logs go to `$CHECK_DIR` and the committed `evidence/` is not touched. Every
105runner needs inputs that are not in the repository: a copy of a cortex-rs database, the
106`cortex-rs` binary, or oracle toolchains. An outside auditor without those cannot run them.
107
108## Known limitations and NOT_RUN
109
110- Hosted CI (`.github/workflows/ci.yml`) compiles both units with the pinned `omc` and produces an
111 SBOM only; the differential, parity, load and concurrency suites are NOT_RUN in CI (they need
112 the oracle inputs above) and run locally through `check.sh`.
113- Parity covers the oracle's wire behaviour; `POST /api/cortex/delete` and `--tokens` are
114 Omega-only extensions and are not in the parity corpus (`spec/PARITY.md`).
115- `tests/` holds Python, C and Rust files used only as oracles and fixture generators.
116- No hardware qualification of any kind; host results only.
117
118## Dependencies and provenance
119
120- Production path: the pinned `omc` only. `build.sh` runs no assembler or linker step; it pipes
121 the unit into `omc` and keeps its output.
122- Test oracles: SQLite 3.45.0 source, `/usr/bin/sqlite3` 3.45.1, gcc, glibc libm, a Rust oracle
123 (serde_json 1.0.151, ryu 1.0.23, chrono 0.4.45, uuid 1.26.1), Python 3, the `cortex-rs` 0.1.0
124 binary (sha256 `91ccba94...98afe` in `spec/PARITY.md`).
125
126## Evidence
127
128Committed under `evidence/`:
129
130- `evidence/parity/summary.txt`: 4,642 records, 4,642 pass, 0 fail, 3,726 masked values, with
131 corpus and binary sha256s; `report.txt` per record; `mutant.txt` gate rc 1 with 172 failing
132 records.
133- `evidence/fts/run.log` (RESULT PASS), `evidence/import/run.log` (PASS=50 FAIL=0),
134 `evidence/json/run.log` (RESULT PASS), each naming the omc sha256.
135- `evidence/load/`: raw latencies, `stats.txt` computed with Wolfram and marked as one unpaired
136 run (indicative, not an A/B speed claim), `crash.txt` (623 acknowledged writes before kill -9,
137 623 present after restart).
138
139These are the author's logs; they are not independent reproduction.