Skip to content

Microsoft.Net.Http.Headers.SetCookieHeaderValue.TryParse throws System.ArgumentOutOfRangeException #61735

Open
@SharanovPavel

Description

@SharanovPavel

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Microsoft.Net.Http.Headers.SetCookieHeaderValue.TryParse throws System.ArgumentOutOfRangeException if Max-Age value is greater than TimeSpan max seconds which is 922337203685.

Expected Behavior

Microsoft.Net.Http.Headers.SetCookieHeaderValue.TryParse returns false and do not throw any exceptions.

Steps To Reproduce

https://github.com/SharanovPavel/setcookieheadervalue-tryparse-overflow-repro

Exceptions (if any)

Unhandled exception. System.ArgumentOutOfRangeException: TimeSpan overflowed because the duration is too long.
   at System.TimeSpan.FromSeconds(Int64 seconds)
   at Microsoft.Net.Http.Headers.SetCookieHeaderValue.GetSetCookieLength(StringSegment input, Int32 startIndex, SetCookieHeaderValue& parsedValue)   
   at Microsoft.Net.Http.Headers.GenericHeaderParser`1.GetParsedValueLength(StringSegment value, Int32 startIndex, T& parsedValue)
   at Microsoft.Net.Http.Headers.BaseHeaderParser`1.TryParseValue(StringSegment value, Int32& index, T& parsedValue)
   at Microsoft.Net.Http.Headers.SetCookieHeaderValue.TryParse(StringSegment input, SetCookieHeaderValue& parsedValue)

.NET Version

9.0.203

Anything else?

Microsoft.Net.Http.Headers version: 9.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions