Transformations
An audit trail holds personal data: user identifiers, IP addresses and the changesets of your entities. The GDPR applies to it.
This page shows the bundle tools. For the mapping to GDPR, ISO 27001 and SOC 2, see Compliance.
Transformations
Control which Doctrine or MongoDB fields go into the stored changeset:
use SymfonyCorp\AuditLog\Attribute\Auditable;
use SymfonyCorp\AuditLog\Attribute\AuditIgnore;
use SymfonyCorp\AuditLog\Attribute\AuditTransform;
#[Auditable]
class User
{
#[AuditIgnore]
public string $token; // not recorded
#[AuditTransform(AuditTransform::HIDDEN)]
public string $password; // recorded as '***'
#[AuditTransform(AuditTransform::HASH)]
public string $externalReference; // recorded as a digest
#[AuditTransform(AuditTransform::KEYED_HASH)]
public string $email; // recorded as a digest keyed with your secret
}| Transformation | Result | Use it for |
|---|---|---|
hidden | *** | Values you never read back: passwords, tokens |
hash | Digest | Values that are not personal data |
keyed_hash | Digest keyed with your secret | Personal data |
The attributes also work on the properties of a Doctrine embeddable or a MongoDB embedded document.
#[AuditTransform] also accepts the name of your own transformer. An unknown name fails cache:warmup. Without a cache warmup, for example in development, the field is recorded as *** and a warning is logged. If a transformer fails, the field is not recorded and a warning is logged. The raw value is never stored.
Pseudonymisation
No transformation anonymises the audit trail. hash and keyed_hash give the same output for the same input, so you can still link the entries of one person. See the CNIL pages on anonymisation and personal data.
- Use
keyed_hashfor an email, a phone number or an IP address in an entity field. A plainhashof such a value is easy to reverse: there are few possible values. keyed_hashcan help with pseudonymisation (GDPR art. 4(5)) if you keep the secret apart from the entries. Store it in the Symfony secrets vault.- The secret must have at least 32 bytes: a short one is easy to find by brute force.
- If you change the secret, new digests no longer match old ones.
symfonycorp_audit_log:
keyed_hash_secret: '%env(AUDIT_KEYED_HASH_SECRET)%'Without the secret, a property that uses keyed_hash fails cache:warmup.
User and IP address
The user and request context providers add the user identifiers and the client IP to each entry. These values are personal data.
anonymize_ipistrueby default:192.168.1.42is stored as192.168.1.0, and IPv6 keeps the first 48 bits. This reduces the data you keep, but the result is not anonymous. Set it tofalseto store the full IP address.- The bundle stores the user identifiers as they are.
- Behind a proxy or a load balancer, set
framework.trusted_proxies. Otherwise,ipis the address of the proxy.
#[AuditTransform] does not apply to these values. To pseudonymise them, change them in a PreAuditLogEvent listener. This listener gives the same digest as keyed_hash:
use SymfonyCorp\AuditLog\Event\PreAuditLogEvent;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener]
final class PseudonymiseAuditContextListener
{
public function __construct(
#[Autowire('%env(AUDIT_KEYED_HASH_SECRET)%')]
#[\SensitiveParameter]
private readonly string $secret,
) {
}
public function __invoke(PreAuditLogEvent $event): void
{
$entry = $event->getEntry();
$context = [];
foreach (['ip', 'user_identifier', 'impersonator_identifier', 'target_user'] as $key) {
if (\is_string($entry->context[$key] ?? null)) {
$context[$key] = hash_hmac('sha256', serialize($entry->context[$key]), $this->secret);
}
}
$event->setEntry($entry->withContext($context));
}
}To find or delete the entries of one person, see Access and erasure.