redact-mbt is a lightweight MoonBit utility library for masking sensitive values before they are printed, logged, or exposed in debug output.
It focuses on one clear job:
redact values before output
preserve enough structure for troubleshooting
keep rules simple and deterministic
stay small enough for direct reuse in CLI tools, services, and scripts
Why This Project Exists
Many projects need to print request headers, callback URLs, .env snippets, or error context during development. Those outputs are useful for debugging, but they often contain:
API keys
bearer tokens
phone numbers
email addresses
passwords
cookies
redact-mbt provides a pure MoonBit implementation for these common redaction tasks so that applications can keep observability without leaking secrets.
MVP Scope
This MVP covers:
full-value masking
edge-preserving masking
email masking
phone masking
token masking
sensitive key detection
header value redaction
header map redaction
query pair redaction
query string redaction
URL query redaction
dotenv line redaction
multi-line dotenv text redaction
Out of scope for the MVP:
cryptographic storage or secret management
encrypted config files
JSON parser integration
reversible masking
customizable rule engines
locale-specific phone parsing
Installation
Add the package to your MoonBit project in the usual way for your workspace setup.
Package metadata:
package name: guan0310/redact
source package path: guan0310/redact/src
Quick Start
let masked_email = @guan0310/redact/src.mask_email("alice@example.com")
let masked_token = @guan0310/redact/src.mask_token("sk-prod-secret-1234")
let masked_url = @guan0310/redact/src.redact_url(
"https://example.com/callback?access_token=abcdef1234567890&page=2",
)
redact-mbt
redact-mbtis a lightweight MoonBit utility library for masking sensitive values before they are printed, logged, or exposed in debug output.It focuses on one clear job:
Why This Project Exists
Many projects need to print request headers, callback URLs,
.envsnippets, or error context during development. Those outputs are useful for debugging, but they often contain:redact-mbtprovides a pure MoonBit implementation for these common redaction tasks so that applications can keep observability without leaking secrets.MVP Scope
This MVP covers:
Out of scope for the MVP:
Installation
Add the package to your MoonBit project in the usual way for your workspace setup.
Package metadata:
guan0310/redactguan0310/redact/srcQuick Start
Expected output style:
a***e@example.comsk-************1234https://example.com/callback?access_token=abcd********7890&page=2API Overview
Primitive Masking
redact_full(value : String) -> StringReplace any non-empty value with[REDACTED].mask_keep_edges(value : String, left : Int, right : Int) -> StringKeep the left and right edges visible and mask the middle with*.Specialized Value Masking
mask_email(email : String) -> StringPreserve the domain and partially mask the account part.mask_phone(phone : String) -> StringPreserve separators and the last 4 digits.mask_token(token : String) -> StringPreserve a recognizable prefix such assk-orghp_, and the last 4 characters.Rule Helpers
normalize_key_name(name : String) -> StringConvert key names to a normalized lowercase underscore form.is_sensitive_key(name : String) -> BoolDetect whether a field name is likely to contain secret material.redact_key_value(key : String, value : String) -> StringChoose a masking strategy based on the key name.HTTP Helpers
redact_header_value(name : String, value : String) -> StringSpecial-casesAuthorizationstyle headers and preserves the auth scheme.redact_headers(headers : Map[String, String]) -> Map[String, String]Apply header redaction across an entire map.URL and Query Helpers
redact_query_pair(pair : String) -> StringRedact a singlekey=valuepair.redact_query_string(query : String) -> StringRedact a full query string such asa=1&token=....redact_url(url : String) -> StringRedact only the query section of a URL and preserve the path and fragment.Dotenv Helpers
redact_env_line(line : String) -> StringRedact a single dotenv-style assignment.redact_env_text(text : String) -> StringRedact all dotenv-style assignments inside a multi-line text block.Usage Examples
1. Masking a single secret
2. Redacting headers before logging
Result:
AuthorizationbecomesBearer sk-************1234X-Request-Idremains unchanged3. Redacting callback URLs
Result:
https://example.com/callback?api_key=sk-************1234&page=2#done4. Redacting dotenv content
Result:
# local envAPI_KEY=sk-************1234TRACE_ID=req-123Redaction Strategy
The library intentionally uses simple, explicit rules:
[REDACTED]BearerThis makes logs safer while still leaving enough information to answer questions like:
Project Structure
File roles:
moon.mod.json: package metadataREADME.md: user-facing overview and usage guideARCHITECTURE.md: design notes and internal structuresrc/moon.pkg.json: MoonBit package configsrc/redact.mbt: implementation and testsValidation
The project is validated with:
Current MVP test coverage includes:
Limitations
Roadmap Ideas
License
MIT