apex-twin 0.29.0: cap evidence_save

APEX_EVIDENCE_MAX_BYTES (default 16 MiB, 0 unlimited) bounds one evidence blob.
Over the cap, t_evidence returns an error that names the variable and the actual
size, writes no file, and writes an audit deny line. --check and capabilities
report evidence_max_bytes.

Tests in a fresh state dir: 500 bytes under a 1000-byte cap is written; 2000
bytes is refused with APEX_EVIDENCE_MAX_BYTES in the message, evidence_list
still shows one file, and the audit has the deny; a limit of 0 accepts the same
2000 bytes. Red proof: disabling the check gives four red checks.

334 checks, coverage 76.9%, release-check green including distcheck.
This commit is contained in:
lotherk committed 2026-11-21 09:36:32 +00:00
1 parent d4192f95e1
commit eebec07b80
9 files changed
+87 -15

No files matched your search

+10 -1
View File
@@ -8,7 +8,16 @@ fields, and state from an older version is read by a newer one.
There are no git tags. The hash next to a version is the commit that introduced
it; the current entry is the commit that adds this section.
## 0.28.0 — 2026-11-21 — this change
## 0.29.0 — 2026-11-21 — this change
- `APEX_EVIDENCE_MAX_BYTES` (default 16 MiB, `0` unlimited) caps `evidence_save`.
An oversized call returns a clear error naming the variable, writes no file,
and is audited as a deny. `--check` and `capabilities` report the limit.
- Tests: 500 bytes under a 1000-byte cap is written; 2000 bytes is refused, no
second file exists, the audit has the deny, and a limit of 0 accepts it.
Red proof: disabling the check gives four red checks.
## 0.28.0 — 2026-11-21 — d4192f9
- The MCP HTTP face is bounded like the proxy: `APEX_HTTP_MAX_CHILDREN` (default
64, max 1024) with SIGCHLD reaping and a 503 `http busy` + audit at the cap.
+6 -5
View File
@@ -30,7 +30,7 @@ separate, explicitly armed switch.
```sh
make # apex-twin, ~239 kB static-ish binary, zero warnings under -Werror
make test # gate audit + 327 end-to-end checks, no mocks
make test # gate audit + 334 end-to-end checks, no mocks
make asan # apex-twin-asan with ASan + UBSan
make test-asan # the whole suite against the sanitizer binary
make gate-audit # static audit: every target-taking tool calls the gate
@@ -314,7 +314,7 @@ bounding set without `CAP_NET_RAW` (connect scans need none).
`--check` answers the operational questions without starting a server:
`rewrite_rules`, `webhook_configured` (a boolean; the URL is never printed),
`proxy_max_children`, `audit_max_bytes`, `http_max_children`,
`http_head_timeout_ms` and the loaded scope, alongside the version and tool count.
`http_head_timeout_ms`, `evidence_max_bytes` and the loaded scope, alongside the version and tool count.
`capabilities` returns the same fields to the model.
## The radio
@@ -351,6 +351,7 @@ APEX_SERIAL=/dev/ttyACM0 APEX_BAUD=115200
| `APEX_AUDIT_MAX_BYTES` | `10485760` | rotate `audit.log` to `.1`; `0` disables |
| `APEX_HTTP_MAX_CHILDREN` | `64` | concurrent MCP HTTP connections before 503 |
| `APEX_HTTP_HEAD_TIMEOUT_MS` | `20000` | request head/body deadline; `0` disables |
| `APEX_EVIDENCE_MAX_BYTES` | `16777216` | `evidence_save` cap; `0` unlimited |
## Files it writes
@@ -379,7 +380,7 @@ finding and the next report no longer mentions it.
make test
```
327 checks, real binary, real DNS, real files written; no mocks. The suite was
334 checks, real binary, real DNS, real files written; no mocks. The suite was
seen red on purpose: with the "no scope" branch disabled by `if (0 && ...)`,
three checks fail, because they assert the *reason* and not merely that an error
came back — a gate that falls through to the next deny branch looks identical
@@ -410,7 +411,7 @@ this host is an SSH forward to another machine, and a foreign server answered
`{"serverInfo":{"name":"koder"}}` while the suite was green.
The suite is also run against `apex-twin-asan` (`make test-asan`), built with
`-fsanitize=address,undefined`. All 327 checks pass with no ASan or UBSan report,
`-fsanitize=address,undefined`. All 334 checks pass with no ASan or UBSan report,
and a separate batch of error paths, network captures and report generation was
run with leak detection on: no leaks. `make analyze` runs `gcc -fanalyzer` over
every translation unit; it was red first on `vendor/libmcp/mcp.h`, where
@@ -481,7 +482,7 @@ the copied scope reason is now bounded with a precision, not left to snprintf.
## Status
0.28.0. Built and run: 45 tools, 327 checks, 340 fuzz cases and 76.9% line
0.29.0. Built and run: 45 tools, 334 checks, 340 fuzz cases and 76.9% line
coverage. The loop closes: a probe captures the exchange as a pair, a finding
points at it, `finding_update` gives it a state, an asset records the host it
came from, `cors_check`/`cookie_audit`/`http_options` turn a web answer into a
+2 -1
View File
@@ -77,7 +77,8 @@ only narrow what the proxy does (the scope gate still runs first).
`APEX_HTTP_MAX_CHILDREN`, default 64 each, max 1024); beyond that they answer
503 and audit. The HTTP face also enforces a head/body deadline
(`APEX_HTTP_HEAD_TIMEOUT_MS`, default 20 s) so half a request cannot hold a
child forever. Per-stage timeouts bound each request,
child forever. `evidence_save` is capped by `APEX_EVIDENCE_MAX_BYTES` (default
16 MiB) so one call cannot fill the disk; the cap is audited when it refuses. Per-stage timeouts bound each request,
but there is no authentication, so a local client can still consume the
allowed slots.
- **Compromised operator credentials.** A stolen shell or SSH key can run the
+1
View File
@@ -205,6 +205,7 @@ of that file — back up first.
| Audit file size | `APEX_AUDIT_MAX_BYTES`, default 10 MiB, rotates to `.1` |
| Concurrent HTTP connections | `APEX_HTTP_MAX_CHILDREN`, default 64, 503 beyond |
| HTTP request deadline | `APEX_HTTP_HEAD_TIMEOUT_MS`, default 20000 |
| Evidence blob size | `APEX_EVIDENCE_MAX_BYTES`, default 16 MiB, `0` unlimited |
## Troubleshooting
+3 -2
View File
@@ -496,12 +496,13 @@ int main(int argc, char **argv)
"\"rewrite_rules\":%d,\"webhook_configured\":%s,"
"\"proxy_max_children\":%d,\"audit_max_bytes\":%d,"
"\"http_max_children\":%d,\"http_head_timeout_ms\":%d,"
"\"scope\":%s}\n", APEX_VERSION,
"\"evidence_max_bytes\":%d,\"scope\":%s}\n", APEX_VERSION,
(unsigned long)g_srv.ntools, g_cfg.home,
apex_rewrite_count(),
g_cfg.webhook[0] != '\0' ? "true" : "false",
g_cfg.proxy_max_children, g_cfg.audit_max_bytes,
g_cfg.http_max_children, g_cfg.http_head_timeout_ms, b.p);
g_cfg.http_max_children, g_cfg.http_head_timeout_ms,
g_cfg.evidence_max_bytes, b.p);
mcp_buf_free(&b);
return 0;
}
+2 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "0.28.0"
#define APEX_VERSION "0.29.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
@@ -78,6 +78,7 @@ typedef struct {
int audit_max_bytes;
int http_max_children;
int http_head_timeout_ms;
int evidence_max_bytes;
size_t max_output;
int dry_run;
} apex_cfg;
+4
View File
@@ -168,6 +168,7 @@ void apex_config_init(void)
g_cfg.audit_max_bytes = 10 * 1024 * 1024;
g_cfg.http_max_children = 64;
g_cfg.http_head_timeout_ms = 20000;
g_cfg.evidence_max_bytes = 16 * 1024 * 1024;
g_cfg.max_output = APEX_MAX_OUT;
g_cfg.dry_run = 0;
@@ -186,6 +187,9 @@ void apex_config_init(void)
g_cfg.http_head_timeout_ms = 0;
if (g_cfg.http_head_timeout_ms > 3600000)
g_cfg.http_head_timeout_ms = 3600000;
env_int("APEX_EVIDENCE_MAX_BYTES", &g_cfg.evidence_max_bytes);
if (g_cfg.evidence_max_bytes < 0)
g_cfg.evidence_max_bytes = 0;
env_int("APEX_BAUD", &g_cfg.baud);
g_cfg.proxy_max_children = 64;
env_int("APEX_PROXY_MAX_CHILDREN", &g_cfg.proxy_max_children);
+20 -4
View File
@@ -703,13 +703,27 @@ static void t_evidence(mcp_conn *c, const mcp_json *args, void *user)
const char *data = mcp_arg_string(args, "data");
char *path;
mcp_buf b;
size_t len;
(void)user;
if (data == NULL) {
mcp_reply_error(c, "data is required");
return;
}
path = apex_evidence_save(label, data, strlen(data));
len = strlen(data);
if (g_cfg.evidence_max_bytes > 0 &&
len > (size_t)g_cfg.evidence_max_bytes) {
char why[256];
snprintf(why, sizeof(why),
"evidence is %lu bytes, limit is %d (APEX_EVIDENCE_MAX_BYTES)",
(unsigned long)len, g_cfg.evidence_max_bytes);
apex_audit("evidence_save", label != NULL ? label : "(evidence)", 0,
0, why, NULL);
mcp_reply_error(c, why);
return;
}
path = apex_evidence_save(label, data, len);
if (path == NULL) {
mcp_reply_error(c, "cannot write the evidence file");
return;
@@ -717,7 +731,7 @@ static void t_evidence(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"evidence\":");
apex_json_str(&b, path);
mcp_buf_printf(&b, ",\"bytes\":%lu}", (unsigned long)strlen(data));
mcp_buf_printf(&b, ",\"bytes\":%lu}", (unsigned long)len);
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
free(path);
@@ -955,11 +969,13 @@ static void t_capabilities(mcp_conn *c, const mcp_json *args, void *user)
(void)apex_rewrite_load();
mcp_buf_printf(&b, ",\"rewrite_rules\":%d,\"webhook_configured\":%s,"
"\"proxy_max_children\":%d,\"audit_max_bytes\":%d,"
"\"http_max_children\":%d,\"http_head_timeout_ms\":%d}",
"\"http_max_children\":%d,\"http_head_timeout_ms\":%d,"
"\"evidence_max_bytes\":%d}",
apex_rewrite_count(),
g_cfg.webhook[0] != '\0' ? "true" : "false",
g_cfg.proxy_max_children, g_cfg.audit_max_bytes,
g_cfg.http_max_children, g_cfg.http_head_timeout_ms);
g_cfg.http_max_children, g_cfg.http_head_timeout_ms,
g_cfg.evidence_max_bytes);
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
+39 -1
View File
@@ -488,6 +488,41 @@ opened = json.loads(text(by_id[11]))
check("report filters by status=open and finds none", opened["findings"] == 0,
opened)
print("\n== evidence limit ==")
ev_home = tempfile.mkdtemp(prefix="apex-evlimit-")
write_scope(ev_home, {"label": "evlimit", "expires": "2099-12-31T23:59:59Z",
"allow_ip": ["192.0.2.0/24"]})
small = "A" * 500
big = "B" * 2000
res, _ = run([
call(1, "evidence_save", label="small", data=small),
call(2, "evidence_save", label="big", data=big),
call(3, "evidence_list"),
call(4, "audit_log", limit=50),
], home=ev_home, extra_env={"APEX_EVIDENCE_MAX_BYTES": "1000"})
by_id = {r.get("id"): r for r in res}
kept_ev = json.loads(text(by_id[1]))
check("evidence under the limit is written",
kept_ev["bytes"] == 500 and os.path.isfile(kept_ev["evidence"]), kept_ev)
check("evidence over the limit is refused", err(by_id[2]), text(by_id[2]))
check("the refusal names the limit",
"APEX_EVIDENCE_MAX_BYTES" in text(by_id[2]), text(by_id[2]))
listed_ev = json.loads(text(by_id[3]))
check("no file was written for the oversized evidence",
len(listed_ev) == 1, listed_ev)
audit = json.loads(text(by_id[4]))
check("the refused evidence is audited",
any(e["tool"] == "evidence_save" and e["decision"] == "deny" and
"limit" in e["reason"] for e in audit),
[e for e in audit if e["tool"] == "evidence_save"][:2])
res, _ = run([
call(1, "evidence_save", label="big2", data=big),
], home=ev_home, extra_env={"APEX_EVIDENCE_MAX_BYTES": "0"})
allowed = json.loads(text(res[0]))
check("a limit of 0 disables the cap",
not err(res[0]) and allowed["bytes"] == 2000, text(res[0])[:160])
shutil.rmtree(ev_home, ignore_errors=True)
print("\n== finding lifecycle ==")
res, _ = run([
call(1, "finding_add", target="example.com", title="Second, with comma",
@@ -2099,6 +2134,8 @@ check("--check reports the audit rotation size",
check("--check reports the HTTP limits",
chk["http_max_children"] == 64 and
chk["http_head_timeout_ms"] == 20000, chk)
check("--check reports the evidence limit",
chk["evidence_max_bytes"] == 16777216, chk)
chk_hook, out_hook = check_json({"APEX_WEBHOOK": "http://127.0.0.1:9/hook"})
check("--check reports the webhook", chk_hook["webhook_configured"] is True,
chk_hook)
@@ -2112,7 +2149,8 @@ check("capabilities reports the operational state",
caps["proxy_max_children"] == 64 and
caps["audit_max_bytes"] == 10485760 and
caps["http_max_children"] == 64 and
caps["http_head_timeout_ms"] == 20000, caps)
caps["http_head_timeout_ms"] == 20000 and
caps["evidence_max_bytes"] == 16777216, caps)
check("capabilities does not leak the webhook URL",
"127.0.0.1:9" not in text(res[0]), text(res[0])[:200])
with open(os.path.join(ops_home, "rewrite.json"), "w") as f: