jvm log forging (#1643)

* jvm log forging

* jvm log forging

* jvm log forging
This commit is contained in:
Abhinab Kanrar
2017-04-13 13:38:01 +05:30
committed by maibin
parent f5991d1eeb
commit 782c5565fe
3 changed files with 489 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
package com.baeldung.logforging;
import org.owasp.esapi.ESAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LogForgingDemo {
private final Logger logger = LoggerFactory.getLogger(LogForgingDemo.class);
public void addLog(String amount) {
logger.info("Amount credited = {}", amount);
}
public static void main(String[] args) {
LogForgingDemo demo = new LogForgingDemo();
demo.addLog(String.valueOf(300));
demo.addLog(String.valueOf(300 + "\n\nweb - 2017-04-12 17:47:08,957 [main] INFO Amount reversed successfully"));
demo.addLog(String.valueOf(encode(300 + "\n\nweb - 2017-04-12 17:47:08,957 [main] INFO Amount reversed successfully")));
}
public static String encode(String message) {
message = message.replace('\n', '_').replace('\r', '_').replace('\t', '_');
message = ESAPI.encoder().encodeForHTML(message);
return message;
}
}