...
Code Block | ||
---|---|---|
| ||
public void logRemoteIPAddress(String name){ Logger logger = Logger.getLogger(""com.organization.Log""); InetAddress machine = null; try { machine = InetAddress.getByName(name); } catch (UnknownHostException e){ Exception e = MyExceptionReporter.handle(e); } catch (SecurityException e){ Exception e = MyExceptionReporter.handle(e); logger.severe(name + ",""," + machine.getHostAddress() + ",""," + e.toString()); } } |
Compliant Solution
...
Code Block | ||
---|---|---|
| ||
// ... catch (SecurityException e){ Exception e = MyExceptionReporter.handle(e); logger.log(Level.FINEST, ""Security Exception Occurred"", e); } |
If the exception contains sensitive information, the custom MyExceptionReporter
class should extract or cleanse it, before returning control to the next statement in the catch
block. (EXC05-J. Use a class dedicated to reporting exceptions)
...
Code Block | ||
---|---|---|
| ||
String str = JOptionPane.showInputDialog(null, ""Enter your occupation: "", ""Tax Help Form"", 1); |
Compliant Solution
As a first step, a filter can be applied to the input to prevent inadvertent logging of sensitive data. In this compliant solution, a check is enforced so that a string of digits from the SSN
field that lies above say the occupation
field, does not accidentally show up in the log files.
Code Block | ||
---|---|---|
| ||
public class MyFilter implements Filter { public boolean isLoggable(LogRecord lr) { String msg = lr.getMessage(); if (msg.matches(""\\d*"")) { // Filters out any digits return false; } return true; } } // Set the filter in main code Logger logger = Logger.getLogger(""com.organization.Log""); logger.setFilter(new MyFilter()); |
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
Wiki Markup |
---|
\[[API 06|AA. Java References#API 06]\]] Class {{java.util.logging.Logger}} \[[Sun 06|AA. Java References#Sun 06]\]] [Java Logging Overview|http://java.sun.com/javase/6/docs/technotes/guides/logging/overview.html] \[[CVE 08|AA. Java References#CVE 08]\]] [CVE-2005-2990|http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-2990] \[[Chess 07|AA. Java References#Chess 07]\]] 11.1 Privacy and Regulation: Handling Private Information \[[MITRE 09|AA. Java References#MITRE 09]\] [CWE ID 532|http://cwe.mitre.org/data/definitions/532.html] ""Information Leak Through Log Files"", [CWE ID 533|http://cwe.mitre.org/data/definitions/533.html] ""Information Leak Through Server Log Files"", [CWE ID 359|http://cwe.mitre.org/data/definitions/359.html] ""Privacy Violation"", [CWE ID 542|http://cwe.mitre.org/data/definitions/542.html] ""Information Leak Through Cleanup Log Files"" |
...
FIO03-J. Specify the character encoding while performing file or network IO 09. Input Output (FIO) FIO31-J. Defensively copy mutable inputs and mutable internal components