The log file alone is not the problem. Just having a file, and be it a binary with a virus in it, is not dangerous at all as long as it is not executed! The same is true for log files: As long as its contents does not trigger any code and misuse it in a way, it is no problem.
As @ahmad already mentioned it becomes a problem if you use something like eval
to display your log file, because that can very well execute code and some dollar sign may allow an attacker to do much more than cross site scripting alone.
But is fopen
necessarily any better? No! Because examples from the past have impressively shown it. One may think that cat
is a safe way to display text on the console, but even that turned out to be wrong and if even the simplest tool to print some text out is broken, you should not trust in anything, right?
In most cases it is not your software alone, which makes something dangerous. It is often the combination with other software, which may be out of your control. Consider for example, that you are not able to inspect every line of code in your newest system updates for potential side effects with your software.
Or let us assume, that you do not have your own server, but you are customer of a web service provider, who takes care for the system configuration as well. Let us further assume, that this service provider cares for security and has some kind of intrusion detection installed, like for example fail2ban. This may all work really well until you introduce your program into the service providers environment (the other way round) and potentially allows an attacker to break fail2ban with something very regex unfriendly to occupy the system as part of a denial of service attack (just guessing here, but the point gets clear, I hope).