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+.
config, env, encryption) by adding an additional layer of protection for string-based secrets in logs/stack traces.HiddenString class enforces immutability (no direct string access), aligning with defensive programming principles in Laravel’s dependency injection and service containers.config('services.api_token') → new HiddenString(config('services.api_token'))).HiddenString objects directly), secrets may still leak via serialization or reflection. Requires discipline in usage.Str::of() or Encrypter for specific use cases?HiddenString gracefully?HiddenString usage (e.g., mocking, assertion helpers)?ApiClientService constructor).HiddenString in FormRequest validation rules for sensitive fields.config() accessors to return HiddenString for secrets (e.g., via a custom ConfigRepository).Encrypter for storage (e.g., HiddenString(Encrypter::decrypt($value))).HiddenString when logging or debugging auth flows.return $this->apiKey; with return new HiddenString($this->apiKey); in a PaymentGateway class.Str::hide() helper (e.g., use function ParagonIE\HiddenString\hidden;).hidden(config('services.stripe_key')).HiddenString::fromPlaintextString() for explicit conversion.HiddenString directly (use {{ $hiddenString->getBytes() }} sparingly).HiddenString in attributes, but ensure serialization (e.g., ->toJson()) doesn’t leak.HiddenString::mask() for logging).openssl, sodium, or Laravel’s hash helpers.HiddenString into constructors where secrets are used (e.g., public function __construct(private HiddenString $apiToken)).HiddenString::unwrap() method for legacy code paths (with deprecation warnings).HiddenString. Use IDE refactoring tools (e.g., PHPStorm’s "Replace" with regex) to automate bulk changes.HiddenString").// DO: new HiddenString($secret); // DON'T: echo $secret;.HiddenString objects instead of raw values, improving security but potentially obscuring debugging.HiddenString::debug() method that returns a masked placeholder (e.g., [REDACTED]).App\Exceptions\Handler to log HiddenString as [SECRET] in error reports.HiddenString instances for immutable secrets (e.g., static readonly HiddenString $apiKey).HiddenString objects as binary blobs (e.g., ->getBytes()) or encrypted strings to avoid serialization issues.HiddenString objects logged directly (e.g., Log::error($hiddenString)).Log::error($hiddenString->mask()) or a custom HiddenStringLogger wrapper.HiddenString (e.g., return response()->json(['token' => $hiddenToken])).->unwrap()) or use Laravel’s JsonSerializable.get_class_vars() or __debugInfo() to extract secrets.__debugInfo() to return empty array in production.HiddenString prevents leaks vs. raw strings.HiddenString").phpstan rules).HiddenString."How can I help you explore Laravel packages today?