Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OData Batch Requests fails to handle duplicate http attributes #2656

Closed
apiaskowski opened this issue Apr 24, 2023 · 5 comments · Fixed by #2705
Closed

OData Batch Requests fails to handle duplicate http attributes #2656

apiaskowski opened this issue Apr 24, 2023 · 5 comments · Fixed by #2705
Labels

Comments

@apiaskowski
Copy link
Contributor

Sending OData batch requests with duplicate http headers will cause an System.ArgumentException that indicates that duplicate http headers are not validated correct.

Assemblies affected

Microsoft.OData.Core 7.15.0

Reproduce steps

Create a basic MVC OData service and enable batch requests.
Submit any batch request, which includes the same http header twice

Expected result

If a duplicate http header has been send, the duplicate header(s) should be ignored or overwrite the previous value.

Actual result

The OData batch requests returns an HTTP 500 error, with the System.ArgumentException: An item with the same key has already been added. Key: .
This is caused by the Microsoft.OData.JsonLight.BatchPayloadItemPropertiesCache which doesn't validate, if an http header already has been added to the headers Dictionary.

@habbes
Copy link
Contributor

habbes commented Apr 25, 2023

@apiaskowski thanks for reporting this. Would you consider contributing a PR to address this?

@habbes habbes added the bug label Apr 25, 2023
@apiaskowski
Copy link
Contributor Author

@habbes my PR bugfix is in preparation.

@apiaskowski
Copy link
Contributor Author

Dear @habbes,

I've got to take back my PR, because of legal reasons with the CLA that have to be sorted out by my employer.
Do you mind, if I suggest you a potential fix, which I've implemented & tested locally?

The issue occurs, because of missing checks in the Microsoft.OData.JsonLight.ODataJsonLightBatchPayloadItemPropertiesCache class, in specific within the method ScanJsonProperties and ScanJsonPropertiesAsync.
All instances of jsonProperties.Add() and headers.Add() should check, if an element already exists in the respective Dictionary.
Depending on the desired handling, either skip duplicate elements or overwrite the element's value (don't forget to read the next Property by the asynchronousJsonReader, if an element is skipped).

Examples:

In addition I've observed potential ArgumentNullException to occur, when the asynchronousJsonReader.ReadPrimitiveValueAsync() returns an null value and afterwards is converted into a string value without check (only occurs for the Async implementation).

Examples:

@apiaskowski apiaskowski changed the title OData Batch Requests fails to handle duplicate http headers Fixed the http attribute handling of Batch Requests May 17, 2023
@apiaskowski apiaskowski changed the title Fixed the http attribute handling of Batch Requests OData Batch Requests fails to handle duplicate http attributes May 17, 2023
@gathogojr gathogojr added the P3 label Jun 5, 2023
@habbes
Copy link
Contributor

habbes commented Jun 8, 2023

@apiaskowski was this issue observed when using JSON batch or Multipart mixed format or both formats?

@apiaskowski
Copy link
Contributor Author

@apiaskowski was this issue observed when using JSON batch or Multipart mixed format or both formats?

We've been using the content-type json and not multipart.
We don't have a scenario for batching with the multipart format.

apiaskowski pushed a commit to apiaskowski/odata.net that referenced this issue Jul 18, 2023
apiaskowski pushed a commit to apiaskowski/odata.net that referenced this issue Jul 18, 2023
@gathogojr gathogojr linked a pull request Jul 25, 2023 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants