GDPR Compliance & IP Masking: Secure Logging in Xeno
Overview of GDPR & Privacy in Xeno Logging
Section titled “Overview of GDPR & Privacy in Xeno Logging”When building enterprise-grade applications, maintaining strict compliance with data privacy regulations such as the GDPR (General Data Protection Regulation) is mandatory. In server-side and distributed environments, logging sensitive user data—such as raw IP addresses, session cookies, authorization headers, or Personally Identifiable Information (PII)—poses severe compliance risks and potential security liabilities.
Xeno solves this architecturally. Regardless of whether you are building a backend service with @xeno-js/core or an application layout, Xeno’s unified logging subsystem (BaseLogger) automatically enforces privacy guardrails out of the box, ensuring that telemetry data remains completely GDPR-compliant without requiring manual sanitization in your business handlers.
Automatic Client IP Masking
Section titled “Automatic Client IP Masking”Under GDPR guidelines, a raw IP address is classified as Personally Identifiable Information (PII) because it can potentially be linked to identify a natural person. Storing unmasked client IPs directly in log files or third-party APM dashboards violates privacy standards.
Xeno handles this transparently at the network ingestion boundary using built-in IP masking algorithms:
- IPv4 Masking: The last octet of an IPv4 address is automatically replaced with an
x(e.g.,192.168.1.150becomes192.168.1.x). - IPv6 Masking: The final segment of an IPv6 address is anonymized with an
x(e.g.,2001:db8::ff00:42:8329becomes2001:db8::ff00:42:x).
This transformation is executed prior to dispatching log payloads to any transport driver (Console, Pino, or Sentry).
GDPR-Safe Context Cleaning (LoggerUtils.toSafeContext)
Section titled “GDPR-Safe Context Cleaning (LoggerUtils.toSafeContext)”When application exceptions or standard logs capture request metadata, they frequently include volatile or highly sensitive objects like raw HTTP transports (req/res), security cookies, and credential tokens.
To prevent accidental data leaks, Xeno’s BaseLogger integrates LoggerUtils.toSafeContext. This utility performs deep sanitization on any context object passed into a log call:
- Excludes Transport Objects: Strips out native server objects (
req,res) to prevent circular JSON serialization errors and memory leaks. - Removes Sensitive Cookies: Strips cookie collections and session identifiers.
- Purges PII: Filters out authorization headers, bearer tokens, and sensitive query parameters.
How It Works Under the Hood
Section titled “How It Works Under the Hood”The sanitization and masking pipeline operates automatically whenever a log method (info, warn, error, debug) is invoked:
- Context Interception: The
BaseLoggercaptures the log message alongside the provided contextual object. - Safe Context Resolution: It executes
LoggerUtils.toSafeContextto scrub cookies, transports, and PII from the metadata dictionary. - IP Anonymization: Network metadata is inspected, and any raw client IP addresses are passed through the masking utility.
- Multi-Driver Broadcast: The sanitized, GDPR-compliant payload is simultaneously broadcast to all active logging clients (e.g., local console, structured Pino streams, or Sentry error tracking).
Example: Writing GDPR-Safe Logs
Section titled “Example: Writing GDPR-Safe Logs”Because context cleaning is handled globally by the framework, your application code remains clean and focused solely on business logic:
import { TOKENS } from '@xeno-js/core'import type { ILogger } from '@xeno-js/core'
export class OrderService { constructor(private readonly _logger: ILogger) {}
public async processOrder(orderId: string, userId: string): Promise<void> { // The logger automatically sanitizes any sensitive context properties this._logger.info(`Processing payment for order: ${orderId}`) }}Support Us
Section titled “Support Us”Xeno is an MIT-licensed open source project. It can grow thanks to the support of these awesome people. If you’d like to join them, please read more at support section