sanitize

package
v1.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package sanitize provides utilities for masking sensitive string values (API keys, tokens, secrets) in log output, error messages, and user-facing responses. It preserves enough of the original value for humans to identify which key is referenced while hiding the secret material in the middle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeString

func SanitizeString(key string, visiblePrefixLength, visibleSuffixLength int) string

SanitizeString masks the interior of key, preserving the first visiblePrefixLength characters and the last visibleSuffixLength characters and replacing the hidden portion with asterisks. The number of asterisks is capped at 4 regardless of the actual hidden length, so the output does not leak information about the key's size.

Special cases:

  • If either length parameter is negative, an empty string is returned as a safety measure (invalid input → no output).
  • If key matches the [safeVocabulary] (empty string, "undefined", "None", "null"), it is returned unmodified.
  • If key is shorter than visiblePrefixLength + visibleSuffixLength, it is returned unmodified because there is nothing to mask.

Examples:

SanitizeString("sk_live_abc123xyz", 7, 3) → "sk_live****xyz"
SanitizeString("short", 3, 3)             → "short"       (too short to mask)
SanitizeString("null", 3, 2)              → "null"        (safe vocabulary)
SanitizeString("abcdef", 0, 0)            → "****"        (fully masked)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL