SAP / SAP/cf-java-logging-support

Feature Request: Automatic Data Masking and Redaction for Sensitive Custom Fields

Aperta
#320 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Java
Stelle
82
Fork
52
Merge medio
4g 13h
PR unite (30g)
17

Descrizione

Currently, if a developer adds a custom field containing sensitive information (e.g., PII, passwords, API tokens) via MDC, the Fluent API, or a ContextFieldSupplier, there is a risk of this data being written to logs in plain text.

This poses a significant security and compliance risk, as sensitive data can be inadvertently exposed in log aggregation platforms. Relying on individual developers to manually sanitize or avoid logging this data is error-prone and not a scalable solution for large teams or enterprise applications.

The logging encoders (JsonEncoder for Logback, JsonPatternLayout for Log4j2) should be extended to automatically mask or redact the values of specified custom fields before they are written to the final JSON log.
This feature should be configurable within the logback.xml or log4j2.xml files, allowing operators to define a list of field keys whose values should always be masked.

A developer or operator would configure a list of sensitive field keys in their logging configuration.

Example with Logback (logback.xml)

<configuration>
    <appender name="STDOUT-JSON" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="com.sap.hcp.cf.logback.encoder.JsonEncoder">
            <!-- New configuration to specify fields to mask -->
            <maskedFields>password,ssn,user_token</maskedFields>
            
            <!-- Optional: Configure the replacement text -->
            <maskValue>[REDACTED]</maskValue>
        </encoder>
    </appender>
    
    <root level="INFO">
        <appender-ref ref="STDOUT-JSON" />
    </root>
</configuration>

Example with Log4j2 (log4j2.xml)

<Configuration>
    <Appenders>
        <Console name="STDOUT-JSON" target="SYSTEM_OUT">
            <JsonPatternLayout>
                <!-- New configuration to specify fields to mask -->
                <maskedFields>password,ssn,user_token</maskedFields>
                
                <!-- Optional: Configure the replacement text -->
                <maskValue>[REDACTED]</maskValue>
            </JsonPatternLayout>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="STDOUT-JSON" />
        </Root>
    </Loggers>
</Configuration>

Given the configuration above, if the application code is:

LOG.atInfo()
   .addKeyValue("user_id", "test-user")
   .addKeyValue("user_token", "abc-def-123-456") // This is a sensitive key
   .log("User logged in successfully");

The expected log output would be:

{
  "level": "INFO",
  "msg": "User logged in successfully",
  "user_id": "test-user",
  "user_token": "[REDACTED]"  // The sensitive value is automatically masked
}

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia ispezionando gli entry point JsonEncoder e JsonPatternLayout, insieme agli esempi di configurazione logback.xml e log4j2.xml descritti nell’issue. Definisci come applicare maskedFields e maskValue ai campi personalizzati, quindi verifica che le chiavi sensibili configurate producano il valore sostitutivo nell’output JSON finale per entrambi i sistemi di logging.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
observability-sre
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.