Skip to content

Commit aaf0fe2

Browse files
committed
validating of request Authorization header as sensitive string
1 parent 41ba319 commit aaf0fe2

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Data/Server/HeaderRule.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ public function __construct(
2626
/**
2727
* @param non-empty-string $key
2828
*/
29-
public function key(string $key, bool $caseSensitive = false): StringRule
29+
public function key(string $key, bool $caseSensitive = false, bool $sensitiveValue = false): StringRule
3030
{
3131
$values = $this->headerValues($caseSensitive);
3232
$values = $values[$caseSensitive ? $key : strtolower($key)] ?? [];
3333
$value = array_pop($values);
34-
return new StringRule($this->exceptionFactory, new RuleChain(), new Validated($value), 'Request header: '.$key);
34+
return new StringRule(
35+
$this->exceptionFactory,
36+
new RuleChain(),
37+
new Validated($value),
38+
'Request header: '.$key,
39+
$sensitiveValue,
40+
);
3541
}
3642

3743
/**
@@ -40,7 +46,7 @@ public function key(string $key, bool $caseSensitive = false): StringRule
4046
* @param callable(StringRule): TMapped $callable
4147
* @return Collection<TMapped>
4248
*/
43-
public function keyOf(string $key, callable $callable, bool $caseSensitive = false): Collection
49+
public function keyOf(string $key, callable $callable, bool $caseSensitive = false, bool $sensitiveValues = false): Collection
4450
{
4551
$values = $this->headerValues($caseSensitive);
4652
$values = $values[$caseSensitive ? $key : strtolower($key)] ?? null;
@@ -50,7 +56,7 @@ public function keyOf(string $key, callable $callable, bool $caseSensitive = fal
5056
new RuleChain(),
5157
new Validated($values),
5258
'Request header: '.$key,
53-
fn (TypedKey $index) => $callable($index->string())
59+
static fn (TypedKey $index) => $callable($index->string($sensitiveValues))
5460
);
5561
}
5662

@@ -62,7 +68,7 @@ public function keyOf(string $key, callable $callable, bool $caseSensitive = fal
6268
public function authorization(string $type): RegexMatch
6369
{
6470
return $this
65-
->key('Authorization')
71+
->key('Authorization', sensitiveValue: true)
6672
->parseRegex('/^' . preg_quote($type, '/') . ' (?P<value>.+)$/')
6773
->match('value')
6874
;

0 commit comments

Comments
 (0)