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

Principle:3641397194 wq Gpt6 Astra Credential Redaction

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

Overview

A data sanitization pattern that recursively replaces secrets (API tokens) and their URL-encoded forms with a `[REDACTED]` placeholder in all values that may cross a trust boundary, preventing credential leakage through logs, IPC, and server echoes.

Description

Credential Redaction is the security practice of ensuring that a secret token — once placed in memory — never appears in any output that could be logged, displayed, or transmitted to an untrusted context. It addresses the problem of credential leakage through server echoes: a server can return a submitted credential in a response body, an error message, or a redirect URL, and any of these could be logged or displayed to the user.

The pattern operates at two levels:

  • String redaction (`_redact`): replaces every occurrence of the raw `authToken` and its `encodeURIComponent`d form with `[REDACTED]` in a string. This catches tokens in error messages and URL fragments.
  • Payload redaction (`_redactPayload`): recursively walks objects and arrays, redacting both keys and values. This catches tokens echoed inside JSON response bodies — even nested deep in the structure.

The pattern is applied at every trust-boundary crossing: before returning data from `_request`/`_requestOpenAI`, before including a URL in `status()`, and before reporting errors.

Usage

Use this principle whenever a value containing a credential may cross from a trusted context (the main process) to a less-trusted context (IPC, renderer, logs, error messages). It is the data-hygiene layer behind the relay adapter's credential isolation guarantee.

Theoretical Basis

The redaction algorithm is a recursive walk with string substitution:

# Abstract algorithm (NOT real implementation)
def redact(value, auth_token):
    if auth_token:
        secrets = {auth_token, url_encode(auth_token)}  # both forms
        for secret in secrets:
            value = value.replace(secret, "[REDACTED]")
    return value

def redact_payload(value, auth_token):
    if isinstance(value, str):
        return redact(value, auth_token)
    if isinstance(value, list):
        return [redact_payload(item, auth_token) for item in value]
    if isinstance(value, dict):
        return {redact(key, auth_token): redact_payload(val, auth_token)
                for key, val in value.items()}
    return value  # numbers, bools, null pass through

Key properties:

  • Two secret forms: both the raw token and its `encodeURIComponent` form are replaced — a token in a URL query string is encoded differently than in a header.
  • Recursive depth: `_redactPayload` walks arbitrarily nested objects/arrays, redacting keys and values at every level.
  • Idempotent: `[REDACTED]` contains no secret, so re-redacting a redacted value is a no-op.
  • Non-destructive to structure: numbers, booleans, and null pass through unchanged — only strings are modified.

Practical Guide

  • The `authToken` is stored only in the frozen `config` object held in main-process memory; it is never sent to the renderer.
  • `status()` calls `_redact` on `baseUrl` and `_publicEndpoint` on endpoint values before returning.
  • `_request` and `_requestOpenAI` call `_redactPayload` on the full response before returning — a server echo is caught.
  • Error messages in `RelayRequestError` are redacted via `_redact` before the message string is constructed.
  • `validateApiUrl` rejects URLs containing the `authToken` at config time — defense in depth before any request is made.

Related Pages

Implemented By

Page Connections

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