dotnet / dotnet/aspnetcore

MEV skips validation for constructor parameters that map to a property in base class

Open
#69,157 1 comment 0 reactions 0 assignees View on GitHub
area-minimal feature-validation
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

```csharp
public abstract record C
{
public int N { get; init; }
protected C(int n) => N = n;
}

public sealed record CDerived : C
{
public string? S { get; init; }

[JsonConstructor]
public AffectedRequest([Range(1, 5)] int n, string? s= null) : base(n) => S = s;
}
```

### Expected Behavior

Validation for `n` is executed.

### Steps To Reproduce

Use `CDerived` in minimal API endpoint and pass invalid value for `n` in request.

### Exceptions (if any)

_No response_

### .NET Version

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the provided C and CDerived records in a minimal API endpoint, passing an invalid value for n. Trace the constructor-parameter validation path for parameters mapped to a base-class property. Done means the [Range(1, 5)] validation on n runs and the invalid request is 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
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.