Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log an Error without leaking any security info or stacktrace?

When I run Fortify Scan on my project i do see that i'm logging the exceptions using

LOGGER.error(e.getMessage(),e);

and it says this is not the right way because attckers may get access to this info and get system info from this and plan an attack.

What is the best way to do this?(without compramising on the security)?

like image 759
Darshan N Reddy Avatar asked Feb 10 '12 08:02

Darshan N Reddy


2 Answers

That reasoning is frankly ridiculous in most cases. Your LOGGER object should be writing to the local filesystem, and if a remote attacker can access your filesystem you've got way bigger problems.

Restrict access to your log files as appropriate, and then log to your heart's content.

like image 94
Steven Schlansker Avatar answered Nov 02 '22 21:11

Steven Schlansker


You could switch logging off in production, but this would make you great disadvantage when the final user would report error and you would have no idea what had happened.

You should treat your logs as critical data and protect access to them on operating system level, such as access to database files. If attacker would access the database, he would compromise the system anyway. At best only the system admin should have access to log files, and should give them to developers only when needed (critical error on production etc.).

like image 40
Danubian Sailor Avatar answered Nov 02 '22 19:11

Danubian Sailor