OData / OData/AspNetCoreOData

Authentication should be done before OData validations

Open
#734 3 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

Assemblies affected
ASP.NET Core OData 8.x

Describe the bug
When calling a secured OData endpoint with wrong authentication, I get a 500 error instead of a 401.
This occurs when using an invalid key in the URL. Example odata/books/aaaaaaa or odata/books/1' when the expected key is an int.

Reproduce steps
I build a new web api project, added OData and basic authentication for testing purposes. View my example here https://github.com/berubejp/odatawebapptest

My issue occurs when I call the endpoint without or with wrong authentication.
When calling odata/books, I get a 401 response as expected.
When calling odata/books/1, I get a 401 response as expected.
When calling odata/books/1', I get a 500 response. Notice the single quote at the end or the URL.
When calling odata/books/aaaaaaa, I get a 500 response.

The error is ODataException: The key value (xx) from request is not valid.
This exception is triggered before the authentication is handled.

Request/Response
Using my example web api, you can call the web api using basic authentication using "admin:admin". However, the issue is triggered if authentication is invalid or absent.

Expected behavior
I would expected the authentication to kick and fail before any OData validations resulting in a 401 response.
The OData validation error should only be triggered if the authentication succeed.

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

Reproduce the behavior in the linked web API example with ASP.NET Core OData 8.x, comparing requests to odata/books, odata/books/1, and malformed keys such as odata/books/1' or odata/books/aaaaaaa. Trace where authentication and OData key validation are handled. Done means unauthenticated requests consistently return 401 before OData validation, while authenticated malformed requests still produce the validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.