Remove sensitive data before sharing a session
Redact or remove sensitive logs, network requests, screenshots, trees, artifacts, and other session content before exporting a portable copy.
Prepare a session for handoff by removing or redacting sensitive content from the exported copy. A sanitizer applies your privacy rules while Ansight writes a portable ZIP, letting you keep useful debugging evidence and leave the original local capture unchanged.
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
ansight-sanitizer.d.ts
declaration and TypeScript configuration when they are missing. Open the
declaration to review its complete source, copy it, or download it.
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)
})),
requestBody: request.requestBody?.encoding === "utf8"
? { ...request.requestBody, data: pii.redact(request.requestBody.data) }
: null,
responseHeaders: [],
responseBody: null
};
};
Return the edited item to keep it or null to remove it from the exported copy.
sanitizeNetworkRequest receives the typed NetworkRequestItem model. It may
rewrite the URL, headers, error fields, sizes, and bounded request or response
bodies, or suppress the entire request. The example redacts a UTF-8 request body
and removes binary request bodies and every response body. Request identity and
timestamps remain protected, and the mandatory network sanitizer runs again
after the TypeScript function returns. See Network Capture
for SDK capture limits and app-side sanitization.
Share context
Every sanitizer receives an operation value so a policy can distinguish a
local export from a share and apply stricter rules to public links:
export const sanitizeNetworkRequest:
AnsightSanitizer.SanitizeNetworkRequest = (request, { operation }) => {
const isPublicWithoutSignIn =
operation.kind === "share" &&
operation.share.audience === "public_no_auth";
return {
...request,
requestBody: isPublicWithoutSignIn ? null : request.requestBody,
responseBody: isPublicWithoutSignIn ? null : request.responseBody
};
};
operation is a discriminated union. An export has kind: "export" and no
share details. A share has kind: "share", a required teamId, and an
audience from the closed SanitizerShareAudience string enum: team,
public_with_auth, or public_no_auth.
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.