question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regex timeout in JwtTokenUtilities with long jwt

See original GitHub issue

Hi, I’ve got this basic code to read a quite big jwt (9MB). I’ve tried the same code in different machines. It’s working well in most of them, but it’s failing in two and there’s now way to make it works.

The error message is The RegEx engine has timed out while trying to match a pattern to an input string. This can occur for many reasons, including very large inputs or excessive backtracking caused by nested quantifiers, back-references and other factors.

I’ve checked the source code and the reason for this is in the class JwtTokenUtilities. In this line there’s an hardcoded 100ms timeout. I think that this was changed from 2s in 2015 and the decision was to make it not configurable.

Is there any other way or any other configuration (maybe in the os level… win10) to check/change in order to make this work?

Here is the test code:

var jwtHandler = new JwtSecurityTokenHandler { MaximumTokenSizeInBytes = 20000000 }; string text = System.IO.File.ReadAllText(@"long_jwt.txt"); var jwt = jwtHandler.ReadJwtToken(text); // throws regex timeout exception

Thanks for your help.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Riff451commented, May 28, 2019

It turned out that updating the project from .net core 2.1 to 2.2 fixes the issue.

0reactions
brentschmaltzcommented, May 31, 2019

@Riff451 good to hear. Sorry for the hassle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regex to match JWT
I don't have experience with Regex and I'm asking for your help. I need a regex to capture the JWT inside the following...
Read more >
Regex.MatchTimeout Property (System.Text. ...
The MatchTimeout property defines the approximate maximum time interval for a Regex instance to execute a single matching operation before the operation ...
Read more >
Setting Regex Timeout Globally Using .NET 6.0 With C# ...
Setting a timeout allows the operation to stop at a configured timeout, rather than running until completion, using resources the entire time.
Read more >
RegEx evaluation should have a time out specified
The rule should raise a warning on all RegEx methods that lack a timeout parameter when an overload with a timeout is available....
Read more >
Regex Timeout Exeption in c# 4.0
I have a long string and one pattern matching regular expression, when i apply regex.matches method on long string it throws a timeout...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found