ODataQueryOptions.Validate do not throw for "cast" function in filter with array when AllowedFunctions set AllowedFunctions.None
Nobody has claimed this yet.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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