Report MA0153 when the type of a logged property or field is classified - #1418
Merged
Merged
Conversation
The parameter, property and field branches of MA0153 had drifted apart: parameters were checked against the type of their value, while properties and fields were only checked against their declaring type. An attribute inheriting from DataClassificationAttribute placed on the type of a logged property or field was therefore ignored, which is the most common way classified data is exposed. The three branches now share a single check that looks at the symbol itself, the type of its value, and, for members, their declaring type. This also applies the report_types_with_data_classification_attributes option to properties and fields, as it was only implemented for parameters. That option is disabled by default.
meziantou
deleted the
feature/do-not-log-classified-data-types-752e0d
branch
September 6, 2026 05:22
This was referenced Sep 6, 2026
Closed
Closed
This was referenced Sep 24, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
MA0153 checked the declaring type for logged properties and fields, but the value type for parameters. An attribute inheriting from
DataClassificationAttributeplaced on the type of a logged property or field was therefore never reported:Since a property or field is the most common way classified data is exposed, the rule gave a false sense of coverage for exactly the data it is meant to protect.
How
The parameter, property and field branches were three near-duplicates that had drifted apart. They now share one
ValidateSymbollocal function that checks, in order:nullfor parameters, whose declaring type is the enclosing method's type and says nothing about the value).Unifying the branches also closed a second hole of the same shape: the
MA0153.report_types_with_data_classification_attributesopt-in — reporting a value whose type contains classified members — was implemented only for parameters, so a property or field of such a type was silently missed even with the option on. It now applies to all three.Reviewer notes
ContainingTypecheck for members is preserved (a new test guards it).Tests
5 cases added to
DoNotLogClassifiedDataAnalyzerTests: attribute on a property's type, on a field's type, on a property's declaring type (regression guard), and the property/type-with-classified-members case with the option both enabled and disabled.21/21 MA0153 tests pass on all five Roslyn versions (4.8, 4.14, 5.0, 5.6, 5.9); the full solution builds with 0 warnings.
dotnet run --project src/DocumentationGeneratorexits 0 with no further changes after thedocs/Rules/MA0153.mdupdate, which documents the three attribute locations and adds a sample.