Skip to content

Commit

Permalink
Add #[\SensitiveParameter] to token and verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
sstok committed Jan 6, 2024
1 parent 661ba98 commit c700405
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Argon2SplitTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null):
return $splitToken->expireAt($this->getExpirationTimestamp($expiresAt));
}

public function fromString(string | HiddenString | \Stringable $token): SplitToken
public function fromString(#[\SensitiveParameter] string | HiddenString | \Stringable $token): SplitToken
{
return Argon2SplitToken::fromString($token);
}
Expand Down
6 changes: 3 additions & 3 deletions src/SplitToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ abstract class SplitToken
private ?string $verifierHash = null;
private ?\DateTimeImmutable $expiresAt = null;

final private function __construct(HiddenString $token, string $selector, string $verifier)
final private function __construct(HiddenString $token, string $selector, #[\SensitiveParameter] string $verifier)
{
$this->token = $token;
$this->selector = $selector;
Expand Down Expand Up @@ -150,7 +150,7 @@ public function expireAt(\DateTimeImmutable $expiresAt = null): static
*
* Note: The provided $token is zeroed from memory when it's length is valid.
*/
final public static function fromString(string | HiddenString | \Stringable $token): static
final public static function fromString(#[\SensitiveParameter] string | HiddenString | \Stringable $token): static
{
if ($token instanceof HiddenString) {
$token = $token->getString();
Expand Down Expand Up @@ -259,5 +259,5 @@ protected function configureHasher(array $config): void
abstract protected function verifyHash(string $hash, string $verifier): bool;

/** Produces a hashed version of the verifier. */
abstract protected function hashVerifier(string $verifier): string;
abstract protected function hashVerifier(#[\SensitiveParameter] string $verifier): string;
}
2 changes: 1 addition & 1 deletion src/SplitTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null):
* return SplitToken::fromString($token);
* ```
*/
public function fromString(string | HiddenString | \Stringable $token): SplitToken;
public function fromString(#[\SensitiveParameter] string | HiddenString | \Stringable $token): SplitToken;
}
5 changes: 4 additions & 1 deletion tests/FakeSplitTokenFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public function it_creates_from_stringable_object(): void
$splitToken = $factory->generate();

$stringObj = new class($splitToken->token()->getString()) implements \Stringable {
public function __construct(private string $value) {}
public function __construct(
#[\SensitiveParameter]
private string $value
) {}

public function __toString(): string
{
Expand Down

0 comments on commit c700405

Please sign in to comment.