Skip to content

Commit 91d9b6c

Browse files
authored
bug #7 Fix verifier must be NULL after creation (sstok)
This PR was merged into the 1.0-dev branch. Discussion ---------- | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Fixed tickets | | License | MIT The `create()` method zeroes the verifier after usage but the property didn't allow a null value Commits ------- 37cd885 Fix verifier must be NULL after creation
2 parents 73099af + 37cd885 commit 91d9b6c

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

phpstan.neon

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ parameters:
1010
- ./tests
1111
excludePaths:
1212
- var/
13-
- templates/
14-
- translations/
1513

1614
ignoreErrors:
17-
- '#Attribute class Symfony\\Contracts\\Service\\Attribute\\Required does not exist#' # Not required
15+
# Not required
16+
- '#Attribute class Symfony\\Contracts\\Service\\Attribute\\Required does not exist#'
17+
18+
# Always set, as it's only NULL after zeroing, which happens later
19+
- '#Parameter \#1 \$verifier of method Rollerworks\\Component\\SplitToken\\SplitToken\:\:hashVerifier\(\) expects string, string\|null given#'

src/SplitToken.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ abstract class SplitToken
9494
protected array $config = [];
9595
private HiddenString $token;
9696
private string $selector;
97-
private string $verifier;
97+
private ?string $verifier;
9898
private ?string $verifierHash = null;
9999
private ?\DateTimeImmutable $expiresAt = null;
100100

@@ -203,6 +203,10 @@ final public function matches(?SplitTokenValueHolder $token): bool
203203
return false;
204204
}
205205

206+
if ($this->verifier === null) {
207+
throw new \RuntimeException('matches() does not work with a SplitToken object when created with create(), use fromString() instead.');
208+
}
209+
206210
return $this->verifyHash($token->verifierHash(), $this->verifier);
207211
}
208212

tests/Argon2SplitTokenTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ public function it_fails_when_creating_holder_with_string_constructed(): void
166166
SplitToken::fromString(self::FULL_TOKEN)->toValueHolder();
167167
}
168168

169+
#[Test]
170+
public function it_fails_matches_when_just_created(): void
171+
{
172+
$splitToken = SplitToken::create(self::$randValue);
173+
174+
$this->expectException(\RuntimeException::class);
175+
$this->expectExceptionMessage('matches() does not work with a SplitToken object when created with create(), use fromString() instead.');
176+
177+
$splitToken->matches($splitToken->toValueHolder());
178+
}
179+
169180
#[Test]
170181
public function it_verifies_split_token(): void
171182
{

0 commit comments

Comments
 (0)