OData / OData/AspNetCoreOData

ODataQueryOptions.Validate do not throw for "cast" function in filter with array when AllowedFunctions set AllowedFunctions.None

Open
#708 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

All versions starting from ASP.NET Core OData 8.0.4+, including 8.0.11.
In 8.0.3 it works correctly.

ODataQueryOptions.Validate method doesn't throw exception when "cast" function is used in $filter when AllowedFunctions set AllowedFunctions.None in ODataValidationSettings

Repro

we have following simple EdmModel:

ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EnableLowerCamelCase();
builder.EntitySet<TestModel>("TestModel");
return builder.GetEdmModel();

 public class TestModel 
    {
        /// <summary>
        /// Gets or sets MyProperty1
        /// </summary>
        public int MyProperty1 { get; set; }

        /// <summary>
        /// Gets or sets Value1
        /// </summary>
        public string Value1 { get; set; }
}

In query validation settings we don't allow any functions:

 var odataValidationSettings = new ODataValidationSettings()
            {
                AllowedFunctions = AllowedFunctions.None,
                AllowedArithmeticOperators = AllowedArithmeticOperators.None,
                AllowedLogicalOperators = AllowedLogicalOperators.All,
                AllowedQueryOptions = AllowedQueryOptions.Filter
                                    | AllowedQueryOptions.OrderBy
                                    | AllowedQueryOptions.Top
                                    | AllowedQueryOptions.SkipToken
                                    | AllowedQueryOptions.Select,
                MaxTop = 1_000,
            };

But following GET request doesn't throw ODataException (it considers filter valid):

http://localhost/testmodel?$filter=cast(value1, 'Int32') in [1,2,3]

while these ones throw exception as expected:
http://localhost/testmodel?$filter=cast(value1, 'Int32') eq 3
http://localhost/testmodel?$filter=abs(value1, 'Int32') in [1,2,3]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ODataQueryOptions.Validate and the AllowedFunctions handling in ODataValidationSettings, then reproduce the three filter queries against the shown TestModel and compare behavior with version 8.0.3. Done means the cast function inside an array filter is rejected when AllowedFunctions.None is configured, while the existing invalid-function cases remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.