Skip to content

fix(data-masking): parse JSON string input when erasing with masking_rules - #8637

Closed
LemonCondor wants to merge 1 commit into
aws-powertools:developfrom
LemonCondor:fix/data-masking-rules-json-string
Closed

LemonCondor wants to merge 1 commit into
aws-powertools:developfrom
LemonCondor:fix/data-masking-rules-json-string

Conversation

@LemonCondor

Copy link
Copy Markdown
Contributor

Issue number: closes #8636

Summary

Changes

erase() already parses JSON string input on the fields= path (_normalize_data_to_parse), but _apply_masking_rules evaluated the rule paths against the raw string, so no rule ever matched. This PR deserializes str input with the configured json_deserializer before the rules are applied, like the fields path.

Test: test_erase_json_string_with_masking_rules in tests/functional/data_masking/required_dependencies/test_erase_data_masking.py. It fails without the fix (DataMaskingFieldNotFoundError); with the fix, the data_masking required_dependencies unit and functional tests pass.

User experience

Before: erase(json.dumps({"email": "john@example.com"}), masking_rules=...) raised DataMaskingFieldNotFoundError, or returned the data unmasked with raise_on_missing_field=False.
After: the email is masked (j****@example.com), as with dict input.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…rules

erase(data, fields=...) accepts a JSON string, but erase(data, masking_rules=...)
ran the JSONPath rules against the raw string, so no path ever matched: it raised
DataMaskingFieldNotFoundError, or returned the data unmasked when
raise_on_missing_field=False.
@LemonCondor
LemonCondor requested a review from a team as a code owner October 19, 2026 10:52
@LemonCondor
LemonCondor requested a review from hjgraca October 19, 2026 10:52
@boring-cyborg boring-cyborg Bot added the tests label Oct 19, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 19, 2026
@sonarqubecloud

Copy link
Copy Markdown

@LemonCondor

Copy link
Copy Markdown
Contributor Author

This is now fixed on develop by #8781 (released in 3.40.0), so I am closing this PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: DataMasking.erase with masking_rules ignores JSON string input

2 participants