Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:3641397194 wq Gpt6 Astra redact

From Leeroopedia
Knowledge Sources
Domains Security, Data_Sanitization
Last Updated 2026-10-26 12:00 GMT

Overview

Concrete tool for recursively redacting API tokens and their URL-encoded forms from strings, objects, and arrays, provided by the ColdBrew Zero relay adapter.

Description

The _redact and _redactPayload methods of RelayAdapter implement the credential redaction pattern. They replace every occurrence of the raw `authToken` and its `encodeURIComponent`d form with `[REDACTED]` in any value that may cross a trust boundary — error messages, status objects, server response bodies, and URL fragments.

_redact(value) operates on a single string: it splits the string on each secret form and joins with `[REDACTED]`.

_redactPayload(value) recursively walks objects and arrays, redacting both keys and values at every nesting level. Numbers, booleans, and null pass through unchanged.

These methods are called at every trust-boundary crossing:

  • `status()` calls `_redact` on `baseUrl` and `_publicEndpoint` on endpoint values.
  • `_request` and `_requestOpenAI` call `_redactPayload` on the full response before returning.
  • Error messages in `RelayRequestError` are redacted via `_redact`.
  • `validateApiUrl` rejects URLs containing the token at config time (defense in depth).

Usage

  • Relay responses: applied to every server response before it crosses IPC to the renderer.
  • Error messages: applied before including error text in thrown errors.
  • Status reports: applied to `baseUrl` and endpoint values in `status()`.
  • Testing: call directly on adapter instances to verify redaction behavior.

Code Reference

Source Location

Signature

// Instance methods on RelayAdapter:
_redact(value: string) -> string
_redactPayload(value) -> redactedValue

// _redact replaces config.authToken and encodeURIComponent(config.authToken)
// with [REDACTED] in the string.
//
// _redactPayload recursively:
//   - string -> _redact(string)
//   - array  -> [_redactPayload(item) for each item]
//   - object -> {_redact(key): _redactPayload(val) for each entry}
//   - other -> unchanged (numbers, booleans, null)

Import

// These are instance methods, not module exports. Access via a RelayAdapter instance:
const { RelayAdapter } = require('./relay-adapter');
const adapter = new RelayAdapter({ mode: 'openai', baseUrl: 'https://...', authToken: 'sk-secret' });
adapter._redact('error with sk-secret inside');
adapter._redactPayload({ nested: { key: 'sk-secret' } });

I/O Contract

Inputs

Name Type Required Description
value string Yes (_redact) Input string that may contain the authToken
value any Yes (_redactPayload) String, array, object, or primitive to recursively redact

Outputs

Name Type Description
_redact returns string Input with all token occurrences replaced by [REDACTED]
_redactPayload returns same type as input Recursively redacted copy of the input

Usage Examples

Redact a String

const { RelayAdapter } = require('./relay-adapter');

const adapter = new RelayAdapter({
  mode: 'openai',
  baseUrl: 'https://api.coldcoffeeai.com/v1',
  authToken: 'sk-secret-key-123'
});

// Token in error message
const msg = adapter._redact('Authorization failed for token sk-secret-key-123');
console.log(msg); // 'Authorization failed for token [REDACTED]'

// URL-encoded token (from query string)
const encodedToken = encodeURIComponent('sk-secret-key-123');
const urlMsg = adapter._redact(`Redirect to ?key=${encodedToken}`);
console.log(urlMsg); // 'Redirect to ?key=[REDACTED]'

Redact a Nested Object

const { RelayAdapter } = require('./relay-adapter');

const adapter = new RelayAdapter({
  mode: 'openai',
  baseUrl: 'https://api.coldcoffeeai.com/v1',
  authToken: 'sk-secret-key-123'
});

// Server echoes the token in a nested response body
const response = {
  status: 'ok',
  data: {
    user: 'sk-secret-key-123',
    metadata: {
      apiKey: 'sk-secret-key-123',
      count: 5,
      active: true
    }
  },
  list: ['sk-secret-key-123', 'other-value']
};

const clean = adapter._redactPayload(response);
console.log(clean.data.user);       // '[REDACTED]'
console.log(clean.data.metadata.apiKey); // '[REDACTED]'
console.log(clean.data.metadata.count);  // 5 (unchanged)
console.log(clean.data.metadata.active); // true (unchanged)
console.log(clean.list[0]);         // '[REDACTED]'
console.log(clean.list[1]);         // 'other-value' (unchanged)

Redact with No Token (Preview Mode)

const { RelayAdapter } = require('./relay-adapter');

const adapter = new RelayAdapter(); // preview mode, no authToken

// With no authToken, _redact is a no-op
const msg = adapter._redact('some text with no secrets');
console.log(msg); // 'some text with no secrets' (unchanged)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment