rod icon indicating copy to clipboard operation
rod copied to clipboard

Avoid panicking if a bad regexp is returned when hijacking using an incorrect pattern

Open rdelcampog opened this issue 1 year ago • 3 comments

Using an incorrect pattern (like **.example.com/**) in the HijackRouter.Add() method will make the program panic instead of returning an error.

Rod Version: v0.114.5

rdelcampog avatar Nov 27 '23 12:11 rdelcampog

Error is usually used for uncontrolled contents such as user input, panic is usually used for static content. Usually this regexp pattern is part of the code, so panic is not that unexpected, what do you think?

if it returns the error what would you do with the error?

ysmood avatar Nov 27 '23 16:11 ysmood

In this context, I'd expect it to raise an error and halt the execution of program.

codespearhead avatar Apr 05 '24 14:04 codespearhead

You can always check the pattern before you pass it to the code.

_, err := regexp.Compile(reg)
if err != nil {
  ...
}

router.Add(reg, ...)

ysmood avatar Apr 17 '24 03:04 ysmood