コンテンツにスキップ

シークレットの編集

記録は git にコミットされるため、シークレットはディスクへ何かを書き込む前に取り除かれます。編集はデフォルトで有効です。プロキシは次のリクエスト/レスポンスヘッダーの値を [REDACTED] に置き換えます:

  • Authorization
  • Cookie
  • Set-Cookie

これは安全です: 再生時のマッチングはこれらのヘッダーを無視するため、編集が再生を壊すことはありません。.mock.json の記録、WebSocket の記録、.har ファイルに適用されます。編集を無効にするには、CLI で --no-redact を渡すか、設定redaction: false を設定します。

一部の Cookie だけが機微な場合は、無害なものを名前で許可します(例: theme や A/B テストの Cookie)。許可された Cookie は Cookie/Set-Cookie 内で値を保持し、それ以外の Cookie は引き続き編集されます。

ログインフローとクレデンシャルを記録から完全に排除するには、プロキシを transparent モードにした Playwright の setup project で認証を実行し、storageStategitignore された auth-state.json に保存して、テストで再利用してください。記録されるリクエストには(編集済みの)セッションヘッダーのみが含まれ、ログインは含まれません。

実際の認証プロバイダーに対する動作するセットアップは認証済みアプリの例を参照してください。

デフォルトのヘッダーは(編集が有効な間)常に適用されます。それに追加できます。

  • --no-redact — シークレットの編集を無効化(デフォルトで有効)。
  • --redact — シークレットの編集を有効化。設定が redaction: false の場合に再有効化するためにのみ必要です。
  • --redact-headers <names> — 追加で編集するヘッダー名(カンマ区切り、デフォルトとマージ)。
  • --redact-body <patterns> — リクエスト/レスポンスのボディから編集する正規表現パターン(カンマ区切り)。
  • --allow-headers <names> — 編集から除外するヘッダー名(カンマ区切り、例: set-cookie)。
  • --allow-cookies <names>Cookie/Set-Cookie 内で編集せず保持する Cookie 名(カンマ区切り)。
Terminal window
# Redaction is already on; also redact an API-key header and "sk_live_..." tokens, keep the theme cookie
test-proxy-recorder http://localhost:8000 \
--redact-headers x-api-key \
--redact-body "sk_live_[a-zA-Z0-9]+" \
--allow-cookies theme,locale

ProxyServer を直接構築する場合:

import { ProxyServer } from 'test-proxy-recorder';
// Passing this object enables redaction; pass `false` (or nothing) to keep it off.
const proxy = new ProxyServer('http://localhost:3000', './recordings', undefined, {
headers: ['x-api-key', 'x-auth'], // extra headers, merged with the defaults
bodyPatterns: [/sk_live_[a-z0-9]+/i], // regexes replaced in request/response bodies
allowHeaders: ['set-cookie'], // never redact these headers
allowCookies: ['theme', 'locale'], // keep these cookies inside Cookie/Set-Cookie
placeholder: '[REDACTED]', // default
});

既存の記録を自分で編集したい場合は、redactSession(session, config) もエクスポートされています。