Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Harden cookie parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarbettini committed May 17, 2016
1 parent 130844c commit 7ec7005
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Stormpath.Owin.Middleware/Internal/CookieParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,22 @@ private static void ParseDelimited(string text, char[] delimiters, Action<string
{
++scanIndex;
}
var name = text.Substring(scanIndex, equalIndex - scanIndex);
var value = text.Substring(equalIndex + 1, delimiterIndex - equalIndex - 1);
callback(
Uri.UnescapeDataString(name),
Uri.UnescapeDataString(value),
state);

try
{
var name = text.Substring(scanIndex, equalIndex - scanIndex);
var value = text.Substring(equalIndex + 1, delimiterIndex - equalIndex - 1);
callback(
Uri.UnescapeDataString(name),
Uri.UnescapeDataString(value),
state);
}
catch (ArgumentOutOfRangeException)
{
// bad cookie data
// todo log
}

equalIndex = text.IndexOf('=', equalIndex + 1);
if (equalIndex == -1)
{
Expand Down

0 comments on commit 7ec7005

Please sign in to comment.