8000 GitHub - clewup/sanitize-proxy: A tiny utility to sanitize and redact sensitive fields in JavaScript/TypeScript objects — perfect for logging, debugging, and safely exposing data.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A tiny utility to sanitize and redact sensitive fields in JavaScript/TypeScript objects — perfect for logging, debugging, and safely exposing data.

License

Notifications You must be signed in to change notification settings

clewup/sanitize-proxy

Repository files navigation

🔒 sanitize-proxy

npm version license build

A tiny utility to sanitize and redact sensitive fields in JavaScript/TypeScript objects — perfect for logging, debugging, and safely exposing data.

✨ Features

  • 🔐 Redacts sensitive keys (like password, token, apiKey)
  • ⚙️ Customizable redact values and key lists
  • 🧼 Strips <script> tags from strings
  • 🛡️ Detects basic XSS payloads
  • 🔁 Handles deep nested objects and arrays
  • 🧠 Ignores circular references

📦 Installation

npm install sanitize-proxy

🚀 Quick Start

import { sanitize } from 'sanitize-proxy';

const input = {
  username: 'alice',
  password: 'secret123',
  profile: {
    token: 'abc-123',
    bio: '<script>alert("xss")</script> Welcome!',
  },
};

const clean = sanitize(input, {
  stripUnsafeHtml: true,
  detectXSS: true,
});

console.log(clean);

Output:

{
    username: 'alice',
    password: '[REDACTED]',
    profile: {
    token: '[REDACTED]',
    bio: '[XSS DETECTED]',
}

⚙️ Options

Option Type Default Description
redact string[] See below List of keys to redact
redactValue string "[REDACTED]" Value used to replace redacted fields
stripUnsafeHtml boolean false Removes <script> tags from string values
detectXSS boolean false Replaces known XSS patterns in strings with [XSS DETECTED]

Default redacted keys:

['password', 'token', 'apiKey', 'ssn']

🧪 Running Tests

npm test

📄 License

MIT


🙋‍♀️ Contributing

  1. Fork this repo

  2. Create your feature branch (git checkout -b feature/awesome)

  3. Commit your changes (git commit -am 'Add awesome feature')

  4. Push to the branch (git push origin feature/awesome)

  5. Open a pull request

About

A tiny utility to sanitize and redact sensitive fields in JavaScript/TypeScript objects — perfect for logging, debugging, and safely exposing data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0