Skip to content

Feature request: allow-list mode for filter and sort properties #108

Open

Description

@pdevito3

Summary

Add an opt-in allow-list mode that restricts filtering and sorting to an explicit set of properties. This complements the existing AllowUnknownProperties and PreventFilter/PreventSort deny-list controls with an allow-list alternative.

Motivation

Today, a consumer must remember to call PreventFilter() or PreventSort() on every property they want to hide. Every property is filterable and sortable by default unless explicitly blocked. For applications with sensitive fields, an allow-list (explicit opt-in per property) is safer by default than a deny-list, because a newly added property does not become queryable by accident.

Proposed behavior

  • Add a configuration option, for example config.UseAllowList() or similar, that switches a given entity or the whole configuration to allow-list mode.
  • In allow-list mode, a property is filterable or sortable only if it has an explicit HasQueryName(...) or an equivalent explicit opt-in call.
  • A filter or sort referencing a property outside the allow-list throws the same UnknownFilterPropertyException/SortParsingException that an unrecognized property throws today.
  • Allow-list mode is opt-in and off by default, so existing consumers see no behavior change.

Context

This came out of a security review of the filter and sort parsers. The review scoped allow-list mode out of the immediate bug-fix work, and recommended tracking it here as a follow-up feature.

Shipped in v1.17.0

Set UseAllowList = true on the configuration. A filter or a sort can then use only the properties that the configuration names: a Property mapping, a derived property, or a custom operation. The setting comes from a new IQueryKitAllowList interface, so a custom IQueryKitConfiguration class does not break. The default is off.

Decisions:

  • Each entry is one full path. Property<Recipe>(x => x.Author.Name) allows Author.Name only. It does not allow Author or Author.Id. Property<Recipe>(x => x.Tags) does not allow Tags.Count. Each nested path needs its own entry, so an app can refuse a member such as StartsAt.Ticks when it leaves that path out.
  • Outside the list, a property is unknown. A filter throws UnknownFilterPropertyException and a sort throws SortParsingException. For a filter with AllowUnknownProperties = true, IgnoredClauseBehavior decides: the clause is ignored, or with Throw (Feature request: setting to ignore or throw for filters and sorts on prevented properties #112) the filter throws.
  • A sort on a custom operation throws SortParsingException. A custom operation has no sort expression.
  • PreventFilter and PreventSort still apply to a property on the list.
  • Public fields stay available in the next major version. The resolver finds public properties and public fields today. The next major version drops only non-public members. To also drop public fields breaks more callers than the fix for private members needs.

Still open, for the next major version

Without the allow-list, a filter can still read a non-public member, for example Hidden == "h". Change the default member lookup to public properties and public fields only. This is a breaking change, so this issue stays open until the next major version.

Activity

  1. pdevito3 commented on Nov 1, 2026

    @pdevito3
    OwnerAuthor

    Examples from a downstream app (QueryKit 1.16.2)

    Today a filter can name a private member of the type. PropertyResolver.ResolveMemberPath also tries non-public properties and fields.

    public class Item
    {
        public string? Title { get; set; }
        public DateTimeOffset StartsAt { get; set; }
        private string? Hidden { get; set; } = "h";
    }
    Filter ParseFilter
    Hidden == "h" Parses, and reads the private property

    A deny list with PreventFilter cannot help here, because the app does not know that it must deny a private property. This is the strongest reason for an allow-list.

    Suggestion

    • In allow-list mode, resolve only public properties.
    • Make public-only the default in the next major version. It is a breaking change, because the non-public lookup is deliberate today.

    Members of a value type, such as Title.Length or CreatedAt.Year, stay available. A provider can translate many of them (Npgsql translates these two). Others fail when the query runs, for example StartsAt.Ticks > 0 gives "The LINQ expression ... could not be translated" in EF Core. An app that wants to refuse such members can leave them out of its allow-list. QueryKit does not need a default rule for them.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions