You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C#: Taint more members of ASP.NET remote flow source types - #23043
Follow-up to #21567 / #21612. Members of types bound from [WebMethod] or action-method parameters are only tainted when they are public auto-implemented properties or public fields. Real binder-populated types often don't fit that, so taint stops at the first such member and flow is lost. From my security researcher point of view I was not fully satisfied.
This PR relaxes CandidateMemberToTaint and the two transitive classes (AspNetRemoteFlowSourceMember, AspNetCoreRemoteFlowSourceMember):
Backing-field properties: a property is accepted if its getter returns an expression reading a field and its setter assigns an expression using value to that field, for example lazy initialization or a null check. Properties that compute a value are still excluded, which keeps the isAutoImplemented guard's intent.
Get-only collections: a plain-data property of collection type is accepted without a setter, since binders such as XmlSerializer and Json.NET call the getter and Add to the returned collection. Get-only non-collections stay untainted.
Base types: members declared on base types of a bound type are now covered (shared helper isMemberOfBoundType).
Constants: const fields are excluded. The extractor does not mark them static, so the transitive rule otherwise taints short.MaxValue and similar.
As noted in the discussion, tainting is type-wide, so these members are tainted wherever the type is used. The change stays narrow for that reason.
Tests extend the existing aspremote and remote flow-source tests. A change note is included.
I'm still not 100% satisfied because for more complex operations in Getter/Setter this would not work. The only way to do it properly would be with TaintTracking I think.
isPlainDataProperty is purely syntactic: the getter must return an expression that reads a field, and the setter must assign an expression using value to that field. It does not follow accessors with several statements:
publicclassModel{privatestringf;// Tainted: the setter assigns `value` directly and the getter returns the field.publicstringSimple{get{returnf;}set{f=value;}}// Not tainted: `value` reaches `f` only through a local variable.publicstringViaLocal{get{varr=f;returnr;}// the returned expression is `r`, not a read of `f`set{vart=value;f=t;}// the assigned expression is `t`, not `value`}// Not tainted: same problem with a branch.publicstringConditional{get{stringr;if(f!=null)r=f;elser="";returnr;}set{vart=value;if(t.Length>0)f=t;}}// Tainted by a syntactic check, but only because `value` appears in the call.publicstringWrapped{get{returnf;}set{f=Normalize(value);}}}
Local data flow (DataFlow::localFlow) would handle ViaLocal and Conditional, because it follows locals and branches. I confirmed it also handles f ?? "" and casts, which the syntactic check misses on the getter side. It would miss Wrapped, because it follows value-preserving steps only, so Trim() and Normalize() end the flow. TaintTracking::localTaint would follow those. However, TaintedMember feeds the taint-step relation, so I expect it to be circular and I haven't tried it.
I would like feedback on whether the extra precision is worth a data-flow dependency inside a candidate-member predicate.
Also taint properties whose accessors wrap a backing field, get-only
properties of collection type, and members inherited from base types.
Skip constants.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The source modeling incorrectly taints copied/computed properties and non-bindable collections while missing request-data flow through properties backed by inherited fields.
Checking only the returned expression still accepts get { backing = "safe"; return backing; } paired with set { backing = value; }. That property always returns a constant, but it now becomes a TaintedMember, introducing qualifier-to-result taint despite the overwrite. Please account for writes that replace the backing field before it is returned, while preserving the supported lazy-initialization case, and add a negative regression case.
Require getter and setter to access the same property receiver
Matching the field declaration does not ensure the getter and setter use the same instance: get { return this.f; } set { other.f = value; } passes this check. Binding that property never changes its returned value, yet the property gains a type-wide taint step. Require both field accesses to target the property receiver (this/base) and add a negative test.
Check unbound accessor shape for constructed generic properties
Constructed generic accessors have no extracted bodies, so isAutoImplementedReadOnly() treats a computed get-only property as auto-implemented. Binding Model<string> with Model<T>.ItemsCopy => new List<T>(items) therefore taints ItemsCopy, although populating the returned temporary list cannot affect subsequent getter calls. Check p.getUnboundDeclaration() for the accessor shape, keeping p for the constructed collection-type check, and add a generic negative test.
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
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.
Hello @michaelnebel
Follow-up to #21567 / #21612. Members of types bound from
[WebMethod]or action-method parameters are only tainted when they are public auto-implemented properties or public fields. Real binder-populated types often don't fit that, so taint stops at the first such member and flow is lost. From my security researcher point of view I was not fully satisfied.This PR relaxes
CandidateMemberToTaintand the two transitive classes (AspNetRemoteFlowSourceMember,AspNetCoreRemoteFlowSourceMember):Addto the returned collection. Get-only non-collections stay untainted.isMemberOfBoundType).As noted in the discussion, tainting is type-wide, so these members are tainted wherever the type is used. The change stays narrow for that reason.
Tests extend the existing aspremote and remote flow-source tests. A change note is included.
I'm still not 100% satisfied because for more complex operations in Getter/Setter this would not work. The only way to do it properly would be with TaintTracking I think.
isPlainDataPropertyis purely syntactic: the getter must return an expression that reads a field, and the setter must assign an expression using value to that field. It does not follow accessors with several statements:Local data flow (
DataFlow::localFlow) would handleViaLocaland Conditional, because it follows locals and branches. I confirmed it also handlesf ?? ""and casts, which the syntactic check misses on the getter side. It would missWrapped, because it follows value-preserving steps only, soTrim()andNormalize()end the flow.TaintTracking::localTaintwould follow those. However,TaintedMemberfeeds the taint-step relation, so I expect it to be circular and I haven't tried it.I would like feedback on whether the extra precision is worth a data-flow dependency inside a candidate-member predicate.