Repository navigation
Description
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/SortParsingExceptionthat 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)allowsAuthor.Nameonly. It does not allowAuthororAuthor.Id.Property<Recipe>(x => x.Tags)does not allowTags.Count. Each nested path needs its own entry, so an app can refuse a member such asStartsAt.Tickswhen it leaves that path out. - Outside the list, a property is unknown. A filter throws
UnknownFilterPropertyExceptionand a sort throwsSortParsingException. For a filter withAllowUnknownProperties = true,IgnoredClauseBehaviordecides: the clause is ignored, or withThrow(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. PreventFilterandPreventSortstill 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
pdevito3 commentedon Nov 1, 2026
Examples from a downstream app (QueryKit 1.16.2)
Today a filter can name a private member of the type.
PropertyResolver.ResolveMemberPathalso tries non-public properties and fields.ParseFilterHidden == "h"A deny list with
PreventFiltercannot 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
Members of a value type, such as
Title.LengthorCreatedAt.Year, stay available. A provider can translate many of them (Npgsql translates these two). Others fail when the query runs, for exampleStartsAt.Ticks > 0gives "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.feat(config): add an opt-in allow-list for filter and sort properties