Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Rules/SensitiveParameterPropagationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ private function resolveCallee(CallLike $node, Scope $scope): ?array
return null;
}

// Wrapping a sensitive value in SensitiveParameterValue is the
// intended safe pattern – never flag it as missing propagation.
if ($type->getObjectClassNames() === ['SensitiveParameterValue']) {
return null;
}

$method = $type->getMethod('__construct', $scope);
$variant = $this->selectVariant($scope, $node, $method->getVariants(), $method->getNamedArgumentsVariants());

Expand Down
7 changes: 7 additions & 0 deletions tests/Fixtures/Propagation/PropagationCases.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\Fixtures\Propagation;

use SensitiveParameter;
use SensitiveParameterValue;

/**
* Test fixture for SensitiveParameterPropagationRule: a parameter marked
Expand Down Expand Up @@ -88,6 +89,12 @@ public function reassignedParameterIsNotFlagged(#[SensitiveParameter] string $pa
$this->nonSensitiveMethod($password);
}

// $value is marked sensitive and wrapped in SensitiveParameterValue - should NOT trigger warning
public function wrappedInSensitiveParameterValueIsNotFlagged(#[SensitiveParameter] string $value): void
{
new SensitiveParameterValue($value);
}

// Helper callee whose parameter is NOT sensitive
public function nonSensitiveMethod(string $password): void
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Propagation/SensitiveParameterPropagationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
$this->analyse([__DIR__.'/../Fixtures/Propagation/PropagationCases.php'], [
[
'Parameter $password is marked #[\\SensitiveParameter] but is passed to a parameter ($password) that is not itself marked with #[\\SensitiveParameter]. Add the attribute there too or ignore with `@phpstan-ignore sensitiveParameter.propagation`.',
24,
25,
],
[
'Parameter $token is marked #[\\SensitiveParameter] but is passed to a parameter ($token) that is not itself marked with #[\\SensitiveParameter]. Add the attribute there too or ignore with `@phpstan-ignore sensitiveParameter.propagation`.',
61,
62,
],
[
'Parameter $secret is marked #[\\SensitiveParameter] but is passed to a parameter ($secret) that is not itself marked with #[\\SensitiveParameter]. Add the attribute there too or ignore with `@phpstan-ignore sensitiveParameter.propagation`.',
67,
68,
],
[
'Parameter $apiKey is marked #[\\SensitiveParameter] but is passed to a parameter ($apiKey) that is not itself marked with #[\\SensitiveParameter]. Add the attribute there too or ignore with `@phpstan-ignore sensitiveParameter.propagation`.',
73,
74,
],
[
'Parameter $secret is marked #[\\SensitiveParameter] but is passed to a parameter ($values) that is not itself marked with #[\\SensitiveParameter]. Add the attribute there too or ignore with `@phpstan-ignore sensitiveParameter.propagation`.',
80,
81,
],
]);
});