-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Description
Summary
Enhance the SensitiveParameter
attribute to support object properties in addition to parameters. This extension aims to improve the security of sensitive data by ensuring that sensitive information within object properties is also redacted in stack traces and other relevant outputs.
The SensitiveParameter
attribute in PHP is currently defined as follows:
This attribute is used to mark a parameter that is sensitive and should have its value redacted if present in a stack trace.
Extend the target of the SensitiveParameter
attribute to include object properties. This would enable developers to mark object properties as sensitive, ensuring their values are redacted in stack traces and other logs where sensitive information should not be exposed.
To bear in mind:
- Sensitive information is often stored not only in function or method parameters but also in object properties. Examples include passwords, API keys, personal identification information, and financial data.
- By extending
SensitiveParameter
to properties, we can ensure a more comprehensive redaction of sensitive data, reducing the risk of sensitive information leakage in stack traces and logs. - Currently, developers need to implement custom solutions to redact sensitive properties. This can lead to inconsistent practices and potential oversights.
- A unified approach through the
SensitiveParameter
attribute provides a standard, consistent way to handle sensitive data across the application.
The implementation would involve modifying the SensitiveParameter
attribute class to support properties. This could be achieved by:
- Updating the attribute targets to include properties.
- Ensuring that the runtime mechanisms responsible for generating stack traces and logs are aware of and respect the
SensitiveParameter
attribute on properties.
Example Usage:
class User
{
#[SensitiveParameter]
public string $password;
#[SensitiveParameter]
private string $apiKey;
public function __construct(
#[SensitiveParameter] string $password,
#[SensitiveParameter] string $apiKey
) {
$this->password = $password;
$this->apiKey = $apiKey;
}
public function authenticate(): bool
{
// Authentication logic
}
}
In this example, both the constructor parameters and the class properties password
and apiKey
are marked as sensitive. When an exception occurs, any stack trace or log containing these properties would redact their values, thus protecting sensitive information.