RazorEngine icon indicating copy to clipboard operation
RazorEngine copied to clipboard

Run timeout for Engine.Razor.Run[Compile]

Open eocron opened this issue 7 years ago • 7 comments

I didn't found Timeout option for RunCompile/Run methods. Not present in configurator either. So Im a little bit in a pinch when it comes to running untrusted code, for example:

while(true){};

It will run forever.

eocron avatar Mar 11 '18 13:03 eocron

Where exactly are you seeing this?

stusklinar avatar Mar 15 '18 08:03 stusklinar

I see this when executing compiled (by razor) dll. For now Im just running it in separated thread and Abort() it to prevent further execution if it times out after one minute.

eocron avatar Mar 26 '18 14:03 eocron

Do you have an example?

stusklinar avatar Mar 26 '18 14:03 stusklinar

Create file example.cshtml with this content:

@
{
    while(true){};
}

And RunCompile it.

eocron avatar Apr 01 '18 11:04 eocron

Yeh that'll break.

I'm not sure if the MS razor engine offers a timeout option.

But, surely all the code should be "trusted" you wouldn't be putting in random views into your code would you?

stusklinar avatar Apr 01 '18 14:04 stusklinar

I stated, that this code will be untrusted - it means I give users rights to modify it. It is used for report generation, and I try not to protect code against hacker or malicious behaviors but from accidents when user made a bug and template will be stuck/overflowed/execute something bad, etc.

eocron avatar Apr 01 '18 14:04 eocron

With a lack of anything here (or in the MS version).

You could write your own, using cancellation tokens? Or set your own timeout

stusklinar avatar Apr 01 '18 14:04 stusklinar