Docs / Privacy & Compliance / Transformations

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:

src/Entity/User.php
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
}
TransformationResultUse it for
hidden***Values you never read back: passwords, tokens
hashDigestValues that are not personal data
keyed_hashDigest keyed with your secretPersonal 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.

config/packages/symfonycorp_audit_log.yaml
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.

#[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:

src/EventListener/PseudonymiseAuditContextListener.php
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.