Skip to main content

redact_url

Function redact_url 

Source
pub fn redact_url(url: &str) -> String
Expand description

Redact credentials from a URL string.

Replaces user:password@ with ***@ while preserving the scheme, host, port, and path for diagnostic purposes. If the URL has no credentials, it is returned unchanged.

This is a best-effort parser that handles common URL formats without requiring a full URL parser dependency. It works on:

  • rtsp://user:pass@host:port/path
  • rtsps://user:pass@host/path
  • http://user:pass@host/path
  • URLs without credentials (returned as-is)

ยงExamples

use nv_core::security::redact_url;

assert_eq!(
    redact_url("rtsp://admin:secret@192.168.1.1:554/stream"),
    "rtsp://***@192.168.1.1:554/stream"
);
assert_eq!(
    redact_url("rtsp://192.168.1.1/stream"),
    "rtsp://192.168.1.1/stream"
);