Bug: DataMasking.erase with masking_rules ignores JSON string input

Aperta Adatta ai principianti
#8,636 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@LemonCondor ci sta già lavorando.

Dal 19/10/2026.

  • #8637 di @LemonCondor — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
aws, python
Ambito
backend, data

Direzione di ricerca

Inizia da aws_lambda_powertools/utilities/data_masking/base.py e leggi _apply_masking_rules e _normalize_data_to_parse per confrontare come le regole di mascheramento e fields= gestiscono l’input di tipo stringa. Esegui la riproduzione fornita e individua i test di mascheramento dei dati per le stringhe JSON. Il lavoro è completato quando l’input di tipo stringa JSON con masking_rules= viene analizzato e i campi corrispondenti vengono mascherati senza modificare il comportamento esistente.

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

Descrizione

Expected Behaviour

DataMasking.erase() accepts a JSON string with fields=. With masking_rules=, the same JSON string input should be parsed too, and the matching fields masked.

Current Behaviour

With masking_rules=, the rule paths are evaluated against the raw string, so nothing ever matches:

  • by default it raises DataMaskingFieldNotFoundError: Field or expression email not found;
  • with raise_on_missing_field=False it only logs a warning and returns the string unmasked.
Code snippet
import json
from aws_lambda_powertools.utilities.data_masking import DataMasking

dm = DataMasking()
rules = {"email": {"regex_pattern": "(.)(.*)(@.*)", "mask_format": r"\1****\3"}}
data = {"email": "[email protected]"}

dm.erase(data, masking_rules=rules)              # {'email': 'j****@example.com'}
dm.erase(json.dumps(data), fields=["email"])     # works, JSON string is parsed
dm.erase(json.dumps(data), masking_rules=rules)  # DataMaskingFieldNotFoundError
Possible Solution

_apply_masking_rules (aws_lambda_powertools/utilities/data_masking/base.py) could deserialize str input with the configured json_deserializer before evaluating the paths, as the fields code path already does in _normalize_data_to_parse.

Steps to Reproduce

Run the snippet above.

Powertools for AWS Lambda (Python) version

latest (3.36.0, also on develop)

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs
aws_lambda_powertools.utilities.data_masking.exceptions.DataMaskingFieldNotFoundError: Field or expression email not found
Lingua principale
Python
Stelle
3.3k
Fork
511
Merge medio
3g 12h
PR unite (30g)
93

Preparare l'ambiente

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.

Altre issue di aws-powertools/powertools-lambda-python

Tutte le issue di aws-powertools/powertools-lambda-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.