Skip to content

Commit

Permalink
Check that regex succeeded and value is an integer. (#2958)
Browse files Browse the repository at this point in the history
Co-authored-by: id4s <user@contoso.com>
  • Loading branch information
brentschmaltz and HP712 authored Aug 1, 2024
1 parent 0fdfc96 commit a596983
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Microsoft.Identity.Web/CookiePolicyOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ bool IsChromiumVersionAtLeast(int major)

// Extract digits from first capturing group.
Match match = Regex.Match(userAgent, regex);
int version = Convert.ToInt32(match.Groups[1].Value, CultureInfo.CurrentCulture);
return version >= major;
if (!match.Success)
return false;

if (int.TryParse(match.Groups[1].Value, out int version))
return version >= major;

return false;
}

bool IsUcBrowser()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void HandleSameSiteCookieCompatibility_CustomFilter_ExecutesSuccessfully(
}

[Theory]
[InlineData(false, "Dalvik / 2.1.0(Linux; U; Android 12; Chromecast Build / STTE.230319.008.H1)")]
[InlineData(true, "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148")]
[InlineData(true, "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1")]
[InlineData(true, "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148")]
Expand Down

0 comments on commit a596983

Please sign in to comment.