Skip to content

Commit a596983

Browse files
brentschmaltzHP712
andauthored
Check that regex succeeded and value is an integer. (#2958)
Co-authored-by: id4s <[email protected]>
1 parent 0fdfc96 commit a596983

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Microsoft.Identity.Web/CookiePolicyOptionsExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,13 @@ bool IsChromiumVersionAtLeast(int major)
152152

153153
// Extract digits from first capturing group.
154154
Match match = Regex.Match(userAgent, regex);
155-
int version = Convert.ToInt32(match.Groups[1].Value, CultureInfo.CurrentCulture);
156-
return version >= major;
155+
if (!match.Success)
156+
return false;
157+
158+
if (int.TryParse(match.Groups[1].Value, out int version))
159+
return version >= major;
160+
161+
return false;
157162
}
158163

159164
bool IsUcBrowser()

tests/Microsoft.Identity.Web.Test/CookiePolicyOptionsExtensionsTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public void HandleSameSiteCookieCompatibility_CustomFilter_ExecutesSuccessfully(
9090
}
9191

9292
[Theory]
93+
[InlineData(false, "Dalvik / 2.1.0(Linux; U; Android 12; Chromecast Build / STTE.230319.008.H1)")]
9394
[InlineData(true, "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148")]
9495
[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")]
9596
[InlineData(true, "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148")]

0 commit comments

Comments
 (0)