Download the PHP package built-fast/phpstan-sensitive-parameter without Composer
On this page you can find all versions of the php package built-fast/phpstan-sensitive-parameter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download built-fast/phpstan-sensitive-parameter
More information about built-fast/phpstan-sensitive-parameter
Files in built-fast/phpstan-sensitive-parameter
Package phpstan-sensitive-parameter
Short Description PHPStan extension for detecting parameters that should use SensitiveParameter
License MIT
Homepage https://github.com/built-fast/phpstan-sensitive-parameter
Informations about the package phpstan-sensitive-parameter
PHPStan SensitiveParameter Detector
A PHPStan extension that detects parameters that might contain sensitive information and should be marked with the #[\SensitiveParameter]
attribute (added in PHP 8.2+).
About SensitiveParameter
The #[\SensitiveParameter]
attribute was introduced in PHP 8.2 to mark sensitive data that should be hidden from stack traces and debugging output. This extension helps you identify parameters that should use this attribute for better security.
Learn more: PHP RFC: Redact parameters in back traces
Requirements
- PHP 8.2 or higher
- PHPStan 2.0 or higher
Installation
Usage
The extension will be automatically registered if you use PHPStan's extension installer.
Alternatively, include the extension in your PHPStan configuration:
What it detects
The rule detects parameters with names containing common sensitive keywords:
- Authentication:
password
,secret
,token
,credential
,auth
,bearer
- API Security:
apikey
(matchesapisecret
,clientsecret
viasecret
) - Financial:
credit
,card
,ccv
,cvv
,ssn
,pin
- Security:
private
,signature
,hash
,salt
,nonce
,otp
,passcode
,csrf
Note: Due to substring matching, secret
catches apisecret
/clientsecret
and token
catches refreshtoken
/accesstoken
.
It works with:
- Regular functions
- Class methods (public, private, protected, static)
- Constructors
- Case-insensitive matching (
Password
,SECRET
, etc.) - Partial matches (
userPassword
,secretKey
, etc.)
Examples
❌ Will trigger warnings:
✅ Properly protected:
Advanced Configuration
To use custom sensitive keywords instead of the defaults, override the service:
This completely replaces the default keyword list with your own.
Suppressing Warnings
You can suppress warnings using PHPStan's ignore comments:
Constructor Parameters
Due to a PHPStan limitation, ignore comments for constructor parameters must be placed before the constructor:
Note: This ignores ALL parameter warnings for that constructor. For functions with multiple parameters where only some are false positives, consider renaming the problematic parameter to avoid the sensitive keyword match.
Common Issues
False Positives
The rule uses substring matching, which can occasionally trigger false positives:
$appInstall
triggers due to "install" containing "pin"$passwordService
triggers due to containing "password"$signatureMethod
triggers due to containing "signature"
For these cases, use ignore comments as shown above or consider renaming
parameters to be more specific (e.g., $applicationToInstall
, $authService
,
$verificationMethod
).
Reporting Issues
Found a bug or have a feature request? Please report it on GitHub.
When reporting issues, please include:
- PHP version
- PHPStan version
- Code sample that demonstrates the issue
- Expected vs actual behavior
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development setup:
Running tests:
License
MIT License - see LICENSE
for details.