certal 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "certal",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Work through the Certal gate: leases, verified batches and operator approvals for every change.",
5
5
  "author": { "name": "Paweł Olszewski" },
6
6
  "repository": "https://github.com/polszewski-pl/certal",
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Fixed
6
+
7
+ - The HTTP transport sent `413` while the client was still sending the body and then closed the connection. On Windows the client could see a reset connection instead of the status. The body is now read and dropped first, up to 32 MiB, and the answer follows.
8
+
3
9
  ## 0.1.4
4
10
 
5
11
  ### Fixed
package/README.md CHANGED
@@ -199,7 +199,7 @@ Witness stages run as child processes. The time limit of a stage is the smaller
199
199
 
200
200
  **The operator.** `certal init` creates an Ed25519 key in `~/.certal/operator.key` and writes the public key to the manifest. `certal approve` signs an approval token for the exact content of one attempt. Every operator command that reaches a running server is signed with the same key, carries a timestamp and a nonce, and is refused without a valid signature. The operator keys are fixed by the first start of a log: a later manifest edit cannot add an approver.
201
201
 
202
- **Agents over HTTP.** The HTTP transport listens on a loopback address only. Every agent named in `--agents` gets a bearer token of its own, and the token alone decides who the caller is. The tokens are files in the operator home, `~/.certal/run/<project id>/agents/<agentId>.token`, not in the project. `certal mcp` prints the directory and removes it when it stops. A request whose `x-certal-agent` header names another agent is refused with `403`. A request above 4 MiB gets `413`, and a request whose content type is not `application/json` gets `415`. A `tools/call` without an id is not run, because the caller could not receive its answer.
202
+ **Agents over HTTP.** The HTTP transport listens on a loopback address only. Every agent named in `--agents` gets a bearer token of its own, and the token alone decides who the caller is. The tokens are files in the operator home, `~/.certal/run/<project id>/agents/<agentId>.token`, not in the project. `certal mcp` prints the directory and removes it when it stops. A request whose `x-certal-agent` header names another agent is refused with `403`. A request above 4 MiB gets `413` after its body was read and dropped (a body above 32 MiB is cut off without an answer), and a request whose content type is not `application/json` gets `415`. A `tools/call` without an id is not run, because the caller could not receive its answer.
203
203
 
204
204
  **Approval channels.** The webhook address must be `https`, or `http` on this machine only. The default channel waits for `certal approve`. The webhook channel posts the binding hash, a summary of the change and the expiry to a URL, and accepts back only a token with a valid operator signature over the same binding.
205
205
 
@@ -16,6 +16,10 @@ export const SUPPORTED_PROTOCOL_VERSIONS = ['2025-06-18', '2025-03-26', '2024-11
16
16
  export const PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[0];
17
17
  /** Largest message that a transport accepts. */
18
18
  export const MAX_MESSAGE_BYTES = 4 * 1024 * 1024;
19
+ /** A request above the limit is read and dropped up to this size, so its sender can get the answer 413. Above it the connection is cut. */
20
+ const MAX_DISCARDED_BYTES = 8 * MAX_MESSAGE_BYTES;
21
+ /** Longest wait for the end of a request that is being dropped. */
22
+ const DISCARD_TIMEOUT_MS = 10_000;
19
23
  export const AGENT_ID_PATTERN = /^[A-Za-z0-9_.-]{1,64}$/;
20
24
  const APPROVAL_REASONS = /APPROVAL/;
21
25
  function nextAction(code, reason, onAllow) {
@@ -509,25 +513,35 @@ export function serveHttp(gateway, listenHost, listenPort, agents = ['agent-1'])
509
513
  const chunks = [];
510
514
  let size = 0;
511
515
  let tooLarge = false;
516
+ let giveUp = null;
512
517
  req.on('data', (chunk) => {
513
- if (tooLarge)
514
- return;
515
518
  size += chunk.length;
519
+ if (tooLarge) {
520
+ // A body far above the limit is not read to its end.
521
+ if (size > MAX_DISCARDED_BYTES)
522
+ req.destroy();
523
+ return;
524
+ }
516
525
  if (size <= MAX_MESSAGE_BYTES) {
517
526
  chunks.push(chunk);
518
527
  return;
519
528
  }
520
- // Answer at once and keep nothing more. The rest of the body is read and dropped for a moment,
521
- // so the client can receive the answer, and then the connection is closed.
529
+ // Nothing more is kept. The rest of the body is read and dropped, and the answer goes out when the
530
+ // client has finished sending. An answer that is sent while the client still writes is lost on
531
+ // some systems: the client sees a reset connection instead of the status.
522
532
  tooLarge = true;
523
533
  chunks.length = 0;
524
- res.writeHead(413, { 'content-type': 'application/json', connection: 'close' });
525
- res.end(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32600, message: `request too large: the limit is ${MAX_MESSAGE_BYTES} bytes` } }));
526
- setTimeout(() => req.destroy(), 1000).unref();
534
+ giveUp = setTimeout(() => req.destroy(), DISCARD_TIMEOUT_MS);
535
+ giveUp.unref();
527
536
  });
528
537
  req.on('end', () => {
529
- if (tooLarge)
538
+ if (tooLarge) {
539
+ if (giveUp)
540
+ clearTimeout(giveUp);
541
+ res.writeHead(413, { 'content-type': 'application/json', connection: 'close' });
542
+ res.end(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32600, message: `request too large: the limit is ${MAX_MESSAGE_BYTES} bytes` } }));
530
543
  return;
544
+ }
531
545
  let message;
532
546
  try {
533
547
  message = JSON.parse(Buffer.concat(chunks).toString('utf8'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "certal",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Deterministic execution firewall and runtime for AI agents. Zero dependencies, SQLite WAL, write-ahead outbox, human-priority undo, and Lean 4 proofs.",
5
5
  "license": "MIT",
6
6
  "author": "Paweł Olszewski",