macaron icon indicating copy to clipboard operation
macaron copied to clipboard

Macaron causes panic on starting gogs/gitea in an unwritable/unreadable directory

Open zeripath opened this issue 6 years ago • 3 comments

Hi!

The init method for macaron causes a panic if the current working directory cannot be read.

https://github.com/go-macaron/macaron/blob/4df59ae8a50bd2e82ed915ff1ce764b1bb128a9d/macaron.go#L315

Because this runs on init even if macaron is not going to be started, if it is linked to a binary it will prevent the binary from starting if it is started in a non-readable working directory.

A workaround is possible but it's not ideal. Is there any way to avoid panicking here?

zeripath avatar Apr 09 '19 21:04 zeripath

Thanks for the feedback!

If working directory is not readable, what's the point of starting the binary?

unknwon avatar Apr 12 '19 00:04 unknwon

If any part of a binary imports macaron then macaron's init will run. So if you have subcommands in your binary, even if that subcommand doesn't need macaron the macaron init will run and will cause a panic.

It may be that we should be separating out our subcommands from the main binary, but in any case panicking in an init is a fairly harsh thing to do. You can't reasonably manage such a situation or provide appropriate logging to the user.

(I could imagine a situation whereby you might want to run in a non-readable working directory but have macaron have its own configuration. That way if there is a security exploit and people are able run a command from your application they will find it very difficult to run anything because their working directory will be unreadable.)

zeripath avatar Apr 12 '19 11:04 zeripath

OK, it makes sense. It indeed kind of annoying.

unknwon avatar Apr 13 '19 03:04 unknwon