Sanitizers

Redact or remove sensitive logs, network requests, screenshots, trees, artifacts, and other session content before exporting a portable copy.

CLI v0.23.1

A sanitizer is a privacy filter for a captured session. It runs while Ansight writes a new portable ZIP and can redact, keep, or remove each supported item. The original local capture is not modified.

Sanitizers are trusted local TypeScript. Review and test them with representative data before relying on them for sharing.

Create a sanitizer

ansight workspace add sanitizer . team-safe

This creates ansight/sanitizers/team-safe.ts plus the generated declaration and TypeScript configuration when they are missing.

The starter module exports named functions for session metadata, logs, network requests, application events, visual trees, screenshots, annotations, analyses, artifacts, and fallback content. You may implement only the functions your policy needs.

Structured content

Use the built-in PII helper for strings or nested values:

import type * as AnsightSanitizer from "./ansight-sanitizer.d.ts";

export const sanitizeLog: AnsightSanitizer.SanitizeLog = (log, { pii }) => {
  return { ...log, message: pii.redact(log.message) };
};

export const sanitizeApplicationEvent:
  AnsightSanitizer.SanitizeApplicationEvent = (event, { pii }) => {
    return pii.redactObject(event);
  };

export const sanitizeNetworkRequest:
  AnsightSanitizer.SanitizeNetworkRequest = (request, { pii }) => {
    return {
      ...request,
      url: pii.redact(request.url),
      requestHeaders: request.requestHeaders.map(header => ({
        ...header,
        value: pii.redact(header.value)
      })),
      responseHeaders: []
    };
  };

Return the edited item to keep it or null to remove it from the exported copy. sanitizeNetworkRequest receives the typed NetworkRequestItem metadata model. It may rewrite the URL, headers, error fields, and sizes, or suppress the entire request. HTTP request and response bodies are never present in the V1 capture. Request identity and timestamps remain protected, and the mandatory network sanitizer runs again after the TypeScript function returns.

Screenshots

Screenshots need image redaction rather than string replacement. A conservative sanitizer combines OCR results with text and bounds already present in the visual tree:

export const sanitizeScreenshot: AnsightSanitizer.SanitizeScreenshot = async (
  screenshot,
  { ocr, image, pii, visualText }
) => {
  const scan = await ocr.scan(screenshot);
  const sensitive = [...scan.blocks, ...visualText]
    .filter(block => pii.matches(block.text));

  if (sensitive.length > 0) {
    return image.redact(sensitive.map(block => block.bounds));
  }

  return scan.available || visualText.length > 0
    ? image.keep()
    : image.redactAll();
};

The final branch fails closed: if neither OCR nor the visual tree could inspect the image, the whole frame is redacted. OCR can miss text, so do not silently keep an uninspectable screenshot in a privacy-sensitive export.

Artifacts

Text artifacts can be redacted. Binary artifacts need an explicit keep/remove decision because the generic PII helper cannot understand their contents:

export const sanitizeArtifact: AnsightSanitizer.SanitizeArtifact = (
  artifact,
  { pii }
) => {
  if (artifact.isBinary) return null;
  return {
    ...artifact,
    content: pii.redact(artifact.content ?? "")
  };
};

Type-check and export

npx tsc -p ansight/sanitizers/tsconfig.json

ansight session sanitize <session-id> sanitized-session.zip \
  --sanitizer ansight/sanitizers/team-safe.ts

You can also sanitize through the export command:

ansight session export <session-id> exported-session.zip \
  --sanitizer ansight/sanitizers/team-safe.ts

Inspect the resulting ZIP before sharing it. Test logs, network requests, screenshots, structured metadata, text artifacts, and binary-artifact behavior—not only the easiest content type.