concept log in category security

This is an excerpt from Manning's book Secure by Design.
Both credit card numbers and SSNs have strong restrictions on how they can be revealed, put into logs, and so on. If they are represented as strings, there’s a risk that they’ll be accidentally put into logs or shown. Later, we’ll see how representing these things as domain classes can avoid such mistakes; for example, by using read-once objects (we cover this in chapter 5).
An example of how to apply the discovery approach on the
shipItemsmethod is shown in listing 12.4. You keep the method signature as is, and for each ambiguous parameter, you try to create the corresponding domain primitive. For the integer valueitemId, you try to create a domain primitiveItemId; for the generically typed billing address, you try to create a domain primitive calledBillingAddress; and so on. For each domain primitive you instantiate, you catch and log any exceptions that can occur. When you’re done, you can start running your test suites and even deploy the code to production. Monitor the logs for errors and address the problems as they occur. Analyze each exception to find the root cause and fix the problem.
Another issue related to logging unchecked strings is leakage of sensitive data in logs due to an evolving domain model. This problem is somewhat hard to recognize unless you know what to look for, so let’s turn back to our previous example, but with a slight modification, as seen in the following listing. What’s been added is the logic for fetching the corresponding table reservation from a repository and a log statement, where the internal data of the matching reservation object is serialized as a
Stringbefore it’s written to the logs.Listing 12.7 Serializing the table reservation object as a
Stringpublic TableReservation fetch(final String reservationId) { logger.info("Fetching table reservation: " + reservationId); final TableReservation tableReservation = repository.reservation(reservationId); #1 logger.info("Received " + tableReservation); #2 return tableReservation; } #1 Fetches a table reservation from the repository #2 Implicitly serializes the table reservation object as a String before being written to the log