NERDVANA has asked for the wisdom of the Perl Monks concerning the following question:
$password= secret(...); ... local $password->{stringify_mask}= undef if ref($password) eq 'Crypt:: +SecretBuffer'; $db= DBI->connect($dsn, $user, $password, \%attr);
On Github, robrwo [suggested a new more functional-programming-like API, namely that a method of SecretBuffer would pass the secret to a callback. My thought on the matter was that the *real* missing feature is a duck-typing API that doesn't need to be specific to SecretBuffer, which should provide an easy and convenient recipe for code that doesn't have a hard dependency on SecretBuffer to gain access to secrets.
I'd like to conduct an informal poll of which design people like the best:
if ($password isa 'Crypt::SecretBuffer') { $db= $password->apply(sub { DBI->connect($dsn, $user, $_[0], \%attr) + }); else { $db= DBI->connect($dsn, $user, $password, \%attr); }
if (blessed $password && $password->can("unmask_secret_to")) { $db= $password->unmask_secret_to(\&DBI::connect, 'DBI', $dsn, $user, + $password, \%attr); } else { $db= DBI->connect($dsn, $user, $password, \%attr); }
$db= DBI->connect($dsn, $user, ref $password? $$password : $password, +\%attr);
I just came up with that scalar-ref idea, and seems pretty safe because no code would normally scalar-dereference a ref unless the ref type was 'SCALAR'. Still, that's drastically lowering the bar for leaking the secret, and isn't advertising that it has this capability...
While pondering your preference, also consider the question "If someone contributed a patch to a module I maintain that added support for receiving secrets via SecretBuffer, how much boilerplate would I be willing to accept?"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Name a method that exposes a secret
by duelafn (Parson) on Sep 30, 2025 at 19:32 UTC |