Bug: DataMasking.erase with masking_rules ignores JSON string input
維護者通常 1 天內回覆
評估
研究方向
從 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=Falseit 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
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
aws-powertools/powertools-lambda-python 的其他 Issue
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocation可能已有人在做 @lechakrawarthy 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 85/100
aws-powertools/powertools-lambda-python#8728 · 4 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GET可能已有人在做 @coughlmao 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 85/100
aws-powertools/powertools-lambda-python#8727 · 4 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 seconds可能已有人在做 @CJstate 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 75/100
aws-powertools/powertools-lambda-python#8726 · 3 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Bug: idempotency payloads with set, frozenset or bytes fields cannot be hashed可能已有人在做 @Neeraj111010 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 80/100
aws-powertools/powertools-lambda-python#8725 · 6 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Bug: with a DynamoDB composite key, DataRecord.idempotency_key is the static partition key value可能已有人在做 @sumedh-aerram 於 1 天前認領。 未關閉bug good first issue help wanted idempotency
難度 2/5 1-3 小時 新手友好度 90/100
aws-powertools/powertools-lambda-python#8724 · 3 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 aws-powertools/powertools-lambda-python 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
aws/sagemaker-python-sdk#6554 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 78/100
huggingface/diffusers#15170 ·
維護者通常 1 天內回覆
-
[BUG] LLM conflict check ignores MNEMOSYNE_LLM_MAX_TOKENS, so reasoning models return empty replies未關閉
難度 2/5 1-3 小時 新手友好度 62/100
mnemosyne-oss/mnemosyne#1325 ·
維護者通常 1 天內回覆
-
enhancement meshtastic-2.8
難度 2/5 1-3 小時 新手友好度 62/100
pskillen/meshflow-api#459 ·