Skip to content

Format Exception: The input string '' was not in a correct format. #2879

@krsnaraja

Description

@krsnaraja

Microsoft.Identity.Web Library

Microsoft.Identity.Web

Microsoft.Identity.Web version

2.19.0

Web app

Sign-in users

Web API

Protected web APIs (validating tokens)

Token cache serialization

Distributed caches

Description

Incorrect regex in IsUcBrowserVersionAtLeast. This bug is creating a lot of exceptions at our code when processing this portion of the code.

Reproduction steps

Have same-site cookie compatibility enabled and try to open web application with userAgent: "Dalvik/2.1.0 (Linux; U; Android 12; Chromecast Build/STTE.230319.008.H1)"

Error message

The input string '' was not in a correct format.

Id Web logs

No response

Relevant code snippets

bool IsUcBrowserVersionAtLeast(int major, int minor, int build)
{
	const string regex = @"UCBrowser\/(\d+)\.(\d+)\.(\d+)[\.\d]* ";

	// Extract digits from three capturing groups.
	Match match = Regex.Match(userAgent, regex);
	int major_version = Convert.ToInt32(match.Groups[1].Value, CultureInfo.CurrentCulture);
	int minor_version = Convert.ToInt32(match.Groups[2].Value, CultureInfo.CurrentCulture);
	int build_version = Convert.ToInt32(match.Groups[3].Value, CultureInfo.CurrentCulture);
	if (major_version != major)
	{
		return major_version > major;
	}

	if (minor_version != minor)
	{
		return minor_version > minor;
	}

	return build_version >= build;
}

Regression

No response

Expected behavior

No exception thrown.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions