paragonie/hidden-string
HiddenString provides a small PHP utility for handling sensitive strings more safely in memory. Extracted from ParagonIE Halite, it helps reduce accidental exposure via debugging/serialization by wrapping secret values in an object. Requires PHP 7+.
HiddenString as a drop-in replacement for raw strings.Adopt if:
Look elsewhere if:
Stringable + custom error handlers (though HiddenString remains more robust for edge cases).Str::mask() or Symfony’s SensitiveProperty, which may suffice for simpler use cases."This is a 5-minute fix to plug a critical security gap: accidental exposure of secrets in error messages. Imagine a developer’s stack trace leaking an API key to a client or a log file left on a server. HiddenString automatically masks sensitive data in all error contexts—logs, Xdebug, Sentry—without changing business logic. It’s used by Paragonie (the team behind libsodium) and costs nothing to implement. For a compliance-heavy project, this is a no-brainer."
*"Need to secure sensitive strings in PHP without rewriting error handling? HiddenString wraps strings in an object that never appears in stack traces or logs, even in edge cases like var_dump() or json_encode(). It’s:
string $password with HiddenString $password in constructors.Tradeoff: Slightly slower string operations (~15% overhead), but the security upside is massive. Let’s add it to our security baseline."*
*"This addresses RFC-2068: Information Exposure Through Debug Output (OWASP Top 10). By encapsulating secrets in HiddenString, we ensure:
try/catch blocks or debug_backtrace().App\Exceptions\Handler.Action: Add to the security checklist for all new PHP services. Pair with paragonie/random_compat for key generation."*
How can I help you explore Laravel packages today?