Skip to content
pleach
Operate

Redaction — credentials and infrastructure detail

A pattern-based redactor runs over error text before it leaves the runtime, rereads each text in layers so an upgrade withholds more and never less, and takes your private host and path names through SessionRuntimeConfig.redaction.

The runtime withholds credentials and private infrastructure detail from the error text it hands back. API keys, credential headers, signed URL queries and private host names are replaced by a marker. Text with nothing to withhold comes back unchanged.

This is a different job from scrubbers. The redactor runs on error text and logs at read time. It needs no compliance package and no registration.

What is withheld

The redactor names families of shapes. It does not publish its patterns, and it withholds the shapes it knows; a secret in a shape it doesn't know reaches the text as written.

FamilyExamplesMarker
Provider keys and tokenssk_live_…, sb_secret_…, AIza…, hf_…, Slack xoxb-…, Supabase sbp_…, AWS key ids[redacted-secret]
Secret-named fieldspassword=, clientSecret: …, "access_token": "…", x-api-key, s3_secret_key[redacted-secret]
Credential headersAuthorization, Cookie:, Set-Cookie:, X-Api-Key: lines[redacted-secret]
Signed URL queriessig=, X-Amz-Signature=, nested or percent-encoded inside another URL[redacted]
Private hostsdb.internal, localhost:5432, a host under a suffix on your roster[redacted-host]
Private addressesIPv4 10/8, 172.16/12, 192.168/16, 127/8, 169.254/16; IPv6 ::1, fc00::/7, fe80::/10, with zones[redacted-host]
Cloud and storage namesARNs, storage URIs, container and Windows paths[redacted-arn], [redacted-storage-uri], [redacted-path]

Each key shape has a length floor, so a bare prefix in prose stays. An AWS secret access key is withheld in key or assignment context, never as a bare 40-character run, so hashes and commit shas stay. A four-part version number that uses private-range numbers (version 10.0.0.1) is withheld, because it can't be told apart from an address.

Encoded and disguised forms

The redactor also reads text written to hide a value:

  • Escaped and serialized text: a secret inside a JSON string, past an escaped quote, up to seven escape levels deep.
  • Percent-encoded, HTML-reference and \uXXXX forms, including an encoded = or dot. The private-host check decodes up to six layers.
  • Invisible and look-alike characters: zero-width characters, the byte-order mark, soft hyphens, bidi controls, fullwidth or dash look-alikes inside a key or host.
  • Values split by a line break or a space, and a value that continues past a marker already in the text.

Output text keeps its original encoding. A token that names no private host (v1%2E2) is left alone.

Length limits

Credentials are redacted over the whole text. The infrastructure patterns run in windows of at most 8,192 characters, cut only at whitespace, so long text is scrubbed before it is cut and a cut can't split a secret. A whitespace-free run longer than 8,192 characters is withheld whole as [redacted-secret].

A serialized value (redactSerializedValue) has a 32,768-character cap. A credential that straddles the cap is redacted before the cut, and a token the cut splits is replaced by [redacted-secret].

Where it applies

SurfaceWhat leaves the runtime
Stream type: "error" eventsThe error text, redacted. code and failureCode are unchanged.
A crashed node in the turn errorThe [Graph] Critical node(s) failed: … text, redacted before it is cut to length.
Failed turn and sub-agent rowsThe failure detail, redacted.
Resume telemetry.error writesRedacted before the cut.
Probes and diagnostic logscode, error_class and message_length. Never the message.

Log and probe lines carry the error's class, an allow-listed code (a SQLSTATE such as 23505) and the message length, because a database or provider message can quote the data it failed on. A name or code that looks like a password, a UUID or a key prefix is reported as custom. Log prefixes are unchanged, so greps over captured logs still match. SessionRuntime shows the console-line format.

Thrown errors, errors returned to callers and event-bus payloads are unchanged.

Configuring it

Pass your private names in SessionRuntimeConfig.redaction; see the redaction option. Extend the defaults rather than replacing them:

import { SessionRuntime } from "@pleach/core";
import {
  DEFAULT_REDACTED_HOST_SUFFIXES,
  DEFAULT_REDACTED_PATH_ROOTS,
  assertRedactionOptions,
  redactInfrastructureDetail,
  type RedactionOptions,
} from "@pleach/core/synthesis";

const redaction: RedactionOptions = {
  hostSuffixes: [...DEFAULT_REDACTED_HOST_SUFFIXES, "corp.example"],
  pathRoots: [...DEFAULT_REDACTED_PATH_ROOTS, "workspace"],
  privateAddresses: true,
};

assertRedactionOptions(redaction); // throws TypeError on a bad roster

const runtime = new SessionRuntime({ storage, redaction });

redactInfrastructureDetail("dial db.corp.example:5432 failed", redaction);
// "dial [redacted-host]:5432 failed"
OptionDefaultEffect
hostSuffixes["internal", "local"]A host ending in .<suffix> becomes [redacted-host]. Scheme, port and path stay.
pathRootsthe default rosterAbsolute paths under these roots are withheld.
privateAddressestruefalse keeps private, shared and loopback addresses visible, for a self-hosted model server. Suffix hosts are still withheld.

assertRedactionOptions throws a TypeError for a roster that isn't an array, an empty array (it would turn that redaction off), an entry that isn't a string or sits outside the host-name character set, a host suffix with no dot such as "com", and a non-boolean privateAddresses. new SessionRuntime({ redaction }) calls it, so a bad roster fails at construction. A child runtime from spawn() inherits the roster.

redactCredentials(text) is the credential half on its own. It takes no options and leaves host names and addresses alone, because in result values they can be legitimate content. Use it where you want secrets gone and infrastructure names kept.

Both redactors read one frozen list of secret field names, shared by the text redactor and the error-context walk. The list isn't a public export, and you can't add names to it.

Fail-closed

If redaction throws, the value is withheld. redactResultValue, redactSerializedValue and redactDisclosureValue return [redacted-secret] instead of propagating. redactCredentials and redactInfrastructureDetail withhold the whole value on an engine RangeError; other errors propagate.

Upgrades only add

Each new reading runs over the output of the earlier ones and can only add markers. An upgrade withholds more and never less. The cost is false positives: a long token-like value you control can read as a secret. Vouch for it with setRedactionKeepList, described under keeping your own ids.

How it differs from scrubbers

Scrubbers rewrite matched spans of event payloads before a row persists, and they target PII and PHI such as SSNs and card numbers. The redactor targets credentials and infrastructure detail, and it covers error text, logs and probes that never become event rows. Run both in a regulated deployment. See Security for the wider checklist.