News for hackers. Stuff that matters.
Re:Log4j RCE Found by janekm on Friday December 10, 2021 @07:51AM (#29509260)
Though of course "debug.log(stuffIGotFromPeer)" is also very common (and as you point out should always be avoided).
Re:Log4j RCE Found by Pxtl on Friday December 10, 2021 @08:57AM (#29509871)
If "debug.log(stuffIGotFromPeer)" is dangerous, then the problem is with debug.log and not my code.

Safe logging is not too high of a bar.

Re:Log4j RCE Found by jhugo on Friday December 10, 2021 @09:05AM (#29509948)
The point is that the first argument is the format string. debug.log("{}", stuffIGotFromPeer) should generally be safe (this bug is an example of when it isn't, though)
Re:Log4j RCE Found by jameshart on Friday December 10, 2021 @10:27AM (#29510971)
The fact that the first argument is interpreted as a format string even when you aren't supplying format arguments is a violation of 'principle of least surprise'. The availability of format parameters that can access environment data - let alone remotely loaded code - is a feature most people won't discover unless they go looking for it.
Re:Log4j RCE Found by rixed on Saturday December 11, 2021 @02:24AM (#29519211)
How are varargs implemented in the JVM ABI? Is the called function even aware of how many parameters were actually passed, or does it have to rely on the format string for that?
Re:Log4j RCE Found by jameshart on Saturday December 11, 2021 @11:54AM (#29522277)
Turned into an object[] array.

The log4j API implements a few overloads of each log method to help avoid the implicit array allocation happening in common logging cases (no args, one arg, etc).

The call site can tell if args were provided.

Re:Log4j RCE Found by watwut on Saturday December 11, 2021 @12:17PM (#29522494)
The format string should not allow remote execution unless explicitly tuned on either.

Logging should not be the thing you have to sanitize.

Re:Log4j RCE Found by smsm42 on Saturday December 11, 2021 @05:40PM (#29524934)
TBH, this is a huge antipattern. You have to put some context in your logs, so it must be something like "debug.log("Got from peer: {}", stuffIGotFromPeer) or something like that. You can't complain printf(stuffIGotFromPeer) is dangerous, so here is the same. But in log4j, debug.log("Got from peer: {}", stuffIGotFromPeer) is as unsafe as the other one, too! There's no way to make it safe, as I understand.
Re:Log4j RCE Found by spion on Sunday December 12, 2021 @06:52AM (#29528843)
Don't see why not. Evaluate the `${}` stuff first, then do the `{}` substitutions.
Re:Log4j RCE Found by lvh on Friday December 10, 2021 @12:17PM (#29512514)
Fortunately (and for reasons I can't begin to understand), debug and info logging levels seem to be safe, but error is not. Technically better, but somehow... morally worse?