Skip to content
Open
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
9 changes: 4 additions & 5 deletions plugins/agent-sdk/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const noop = { info() {}, warn() {} };
* accidentally lands in an error message (defense-in-depth, the same
* shape evercli's output.redact uses).
*/
// Token regex: case-insensitive on both alphabet AND prefix. Current
// issuance is lowercase hex but defense-in-depth covers a future
// alphabet change without us having to chase every log/error sink.
const evtRe = /evt_[a-zA-Z0-9]{32}/g;
const emkRe = /emk_[a-zA-Z0-9]{32}/g;
// Match evercli's output.redact: ≥20 chars, tolerate _/- so a future
// key-format change (and any non-32-char token) is still masked (#7).
const evtRe = /evt_[A-Za-z0-9_\-]{20,}/g;
const emkRe = /emk_[A-Za-z0-9_\-]{20,}/g;

// AWS S3 presigned-POST / GET URLs carry short-lived but real
// credentials. The query-string fields below are issued for ~15 min
Expand Down
15 changes: 14 additions & 1 deletion plugins/agent-sdk/tests/client.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, describe, beforeEach } from "node:test";
import assert from "node:assert/strict";
import http from "node:http";
import { createClient, EvermeError } from "../src/client.js";
import { createClient, EvermeError, redactError } from "../src/client.js";

/**
* Helper: spin up a tiny HTTP server, return its base URL + a
Expand Down Expand Up @@ -110,6 +110,19 @@ describe("client", () => {
}
});

test("redactError masks non-32-char and hyphenated evt_/emk_ tokens", async (t) => {
t.after(async () => s.close());
const hyphen = "evt_abcdefghij-klmnopqrs"; // 20+ with hyphen, used to leak
const shortish = "emk_" + "A".repeat(20);
const long = "evt_" + "b".repeat(40);
const got = redactError(`leaked ${hyphen} and ${shortish} and ${long}`);
assert.equal(got.includes(hyphen), false);
assert.equal(got.includes(shortish), false);
assert.equal(got.includes(long), false);
assert.match(got, /evt_abcd_REDACTED/);
assert.match(got, /emk_AAAA_REDACTED/);
});

test("query params are appended", async (t) => {
t.after(async () => s.close());
const c = createClient({ baseUrl: s.baseUrl, agentId: "x", agentToken: "evt_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" });
Expand Down