Bug: DataMasking.erase with masking_rules ignores JSON string input

未關閉 適合新手
#8,636 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@LemonCondor 已經在處理了。

開始於 2026年10月19日。

  • #8637 來自 @LemonCondor —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
84/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
aws, python
領域
backend, data

研究方向

從 aws_lambda_powertools/utilities/data_masking/base.py 開始,閱讀 _apply_masking_rules 和 _normalize_data_to_parse,比較遮罩規則和 fields= 如何處理字串輸入。執行提供的重現步驟,並找出針對 JSON 字串的資料遮罩測試。完成標準是:使用 masking_rules= 的 JSON 字串輸入會被解析,符合條件的欄位會被遮罩,且不改變現有行為。

由索引模型根據 Issue 內容生成。

描述

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
主要語言
Python
星號
3.3k
分支
511
平均合併
3 天 8 小時
30 天內合併 PR
92

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws-powertools/powertools-lambda-python 的其他 Issue

查看 aws-powertools/powertools-lambda-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。