Download the PHP package globyapp/hash-sensitive without Composer
On this page you can find all versions of the php package globyapp/hash-sensitive. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download globyapp/hash-sensitive
More information about globyapp/hash-sensitive
Files in globyapp/hash-sensitive
Package hash-sensitive
Short Description Monolog processor to protect sensitive information from logging by hashing the values
License MIT
Informations about the package hash-sensitive
Hash Sensitive
Monolog processor to protect sensitive information from logging by hashing the values.
Summary
- About
- Features
- Requirements
- Installation
- Examples
- API
- Known issues
- Thanks
About
A Monolog processor that protects sensitive data from miss logging. Forked from: redact-sensitive by Leo Cavalcante. When redacting values from logs, it might be useful to be able to compare redacted values that are equal.
Avoids logging something like {"api_key":"mysupersecretapikey"}
by substituting the value by a hashed version of the value:
Features
- Adds a monolog processor to hash pre-determined array keys.
- Hashes sensitive data in the monolog context to prevent sending secrets to the logs.
- The hashed version is deterministic and thus allows for correlation between errors.
Requirements
- PHP >= 8.1.0
- Composer
- Monolog >= 3.0
Installation
Add the package to your dependencies:
Usage
1. Prepare your sensitive keys
It is an array of key names, for example:
Will hash the value of the api_key
. Because of PHP's tendency to automatically add integer indexes to such an array,
integers in sensitive keys will be ignored and might lead to unexpected results. To be on the safe side, only use
sensitive string keys, or a nested tree of strings.
2. Create a Processor using the keys
You can now create a new Processor with the given keys:
3. Set the Processor to a Monolog\Logger
Examples
Using the library standalone
It is possible to use the logic in the library without using it as a monolog hook. This can be achieved by constructing a new instance of the Hasher
class.
function scrubKeys
, an array of values to scrub and the sensitive key array can be specified in the same manner as when using the library with monolog.
I don't want my output to be hashed, just replaced with a pre-determined string
If you're looking for formating the output with a user defined string, this isn't the right project. You might want to look into redact-sensitive.
API
Length limit & algorithm
Use lengthLimit
to truncate redacted sensitive information, such as lengthy tokens. Truncation always happens before hashing.
Use algorithm
to specify the algorithm used for hashing the value. Refer to the php documentation for a list of supported algorithms.
Nested values
It should work with nested objects and arrays as well. For more granular control over how nested values are handled,
the exclusiveSubtree
boolean can set. When set to true, this causes the algorithm to, if there is a subtree specified
in the sensitive keys, only check the subtree in the values against keys in that subtree of the sensitive keys.
This is the default behavior.
When set to false, every key in the input data is checked against every key in sensitive keys.
exclusiveSubtree = true:
(test
is not hashed, because test_subkey
specifies a subkey configuration in $sensitive_keys
in which only to_hash
is hashed).
exclusiveSubtree = false:
(test
is hashed, because test
is a key in $sensitive_keys
).
Known issues
Currently, there are no known issues.
Thanks
Feel free to open any issues or PRs.
MIT © 2024