Skip to content

C#: Remote flow source members miss properties with backing fields, get-only collections and inherited members #23150

Backlog

Description

@hugo-syn

Description

For ASP.NET and ASP.NET Core remote flow sources, TaintedMember only taints a narrow set of members on bound model types. Binders such as the MVC model binder and XmlSerializer also populate other kinds of members, so some request data flows through them without CodeQL seeing it. This causes false negatives in the C# security queries.

Missing cases

  1. Properties that wrap a backing field. The getter returns the field and the setter assigns value to it, for example get { return f ?? ""; } set { f = value; }. Only auto-implemented properties were tainted.
  2. Get-only collection properties. Binders add elements in place, for example public List<string> Items { get; } = new();. This also covers properties that return a backing field or use lazy initialisation (items ??= new()).
  3. Members inherited from a base type. This includes properties whose backing field is declared on a base class.
  4. Constants. const fields are currently treated as candidates, but they can never carry request data.

Cases that must stay untainted

  • Properties whose getter computes a value, such as => new List<T>(items) or backing + "x".
  • Properties whose setter ignores value.
  • Getters that overwrite the field before returning it.
  • Getters and setters that access the field on different instances.
  • Get-only arrays, which binding cannot modify.

Proposed fix

Extend CandidateMemberToTaint and AspNetRemoteFlowSourceMember in csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Remote.qll to cover the cases above. Add test coverage in library-tests/dataflow/flowsources/{aspremote,remote} and a change note.

Known limitation

Read-only collection types such as SynchronizedReadOnlyCollection<T> still qualify, because they inherit from ICollection<T> and CollectionType can't distinguish them.

Implemented in #23043.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions