URL Safe Logger

2.0.0 · abandoned · verified Wed Apr 22

The `url-safe` package provides a minimalist utility for sanitizing URLs by removing or masking the authentication (username:password) part. This is primarily used to prevent sensitive credentials from being exposed in logs or other less secure outputs. The current stable version is `2.0.0`, which was released on 2015-07-23. The package has seen no further releases or active development since then, indicating it is no longer maintained. Its key differentiator is its singular focus on URL sanitization for logging, leveraging Node.js's built-in `url` module. Developers should be aware of its age and lack of modern updates when considering its use in contemporary projects. Alternatives often involve more robust URL parsing and manipulation libraries or custom regex-based solutions for sensitive data removal.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `url-safe` to strip or mask the authentication portion of URLs for logging.

const urlSafe = require('url-safe');

const sensitiveUrl1 = 'http://user:pass@example.com/path?query=abc#hash';
const sensitiveUrl2 = 'https://admin:secret@api.service.com/data';
const sensitiveUrl3 = 'ftp://anonymous:ftp@example.org';

console.log('Original URL 1:', sensitiveUrl1);
console.log('Safe URL 1 (default):', urlSafe(sensitiveUrl1));
// Expected: http://example.com/path?query=abc#hash

console.log('\nOriginal URL 2:', sensitiveUrl2);
console.log('Safe URL 2 (masked with ***):', urlSafe(sensitiveUrl2, '***'));
// Expected: https://***@api.service.com/data

console.log('\nOriginal URL 3:', sensitiveUrl3);
console.log('Safe URL 3 (masked with [REDACTED]):', urlSafe(sensitiveUrl3, '[REDACTED]'));
// Expected: ftp://[REDACTED]@example.org

// Example with no auth part
const plainUrl = 'https://www.google.com';
console.log('\nPlain URL:', plainUrl);
console.log('Safe Plain URL:', urlSafe(plainUrl));
// Expected: https://www.google.com

view raw JSON →