- What: A blog post discusses methods to prevent secrets from being logged
- Impact: Offers guidance for developers and system administrators
Keeping Secrets Out of Logs Posted on Aug 2, 2024 tl;dr: There's no silver bullet, but if we put some "lead" bullets in the right places, we have a good shot at keeping sensitive data out of logs. "This is the blog version of a talk I gave at LocoMocoSec 2024. Itās mostly a lightly edited transcript with some screenshots, so if youād prefer, you can watch the video or just flip through the slides ." This post is about how to keep secrets out of logs, and my claim is that (like many things in security) there isnāt a singular action or silver bullet that lets you do this. I would go so far as to say that thereās not even an 80/20 rule, where one action fixes 80% of the problem. Itās not like preventing SQL injection with prepared statements or preventing buffer overflows by using memory-safe languages. What I will offer instead, are lead bullets, of which there are many. Iām going to talk about 10 of them. They are imperfect and sometimes unreliable things that, if put in the right places and with defense-in-depth, can still give us a real good chance at succeeding. My hope is that by the end, youāll have a slightly better framework for how to reason about this problem and some new ideas to add to your kit. Table of contents: The Problem Causes 𤦠Direct logging š° Kitchen sinks š§ Configuration changes š„§ Embedded secrets š” Telemetry šŗš» User input Fixes (lead bullets) š Data architecture š Data transformations šŖØ Domain primitives Compile-time Run-time Run-time: part deux š Read-once objects š Taint checking Awesome Not awesome šļø Log formatters š§Ŗ Unit tests šµļø Sensitive data scanners Sampling š¤ Log pre-processors 𦸠People Recap Strategy 0. Lay the foundation 1. Understand the data flow 2. Protect at chokepoints 3. Apply defense-in-depth 4. Plan for response and recovery Conclusion The Problem With that, letās dive in and set the table by talking about the problem with secrets in logs. So, there are some problems that are annoying. And there are some problems that are difficult. This is both. Iām gonna level with you: I absolutely hate this problem. But Iām not going to gaslight you and tell you that this is the most important thing to work on worry about, because it probably isnāt! You have somewhere between 5 and 50 other problems in your backlog that seem more important, 1 of which you found out about this morning. But I think itās likely that none of those problems are nearly as annoying. While researching this topic, I interviewed about a dozen other engineers and, on this point, they unanimously agreed! Nobody likes dealing with secrets in logs because it is extraordinarily annoying . This is a problem thatās also difficult, but not even in the fun sense, like being technically complex or interesting. Once you catch sensitive data in logs, itās usually pretty straightforward (at least in retrospect) to determine how they got there. But, itās also surprisingly elusive to prevent, and it crops up in incredibly unexpected places and ways. Secrets could mean lots of different things to lots of different teams, but Iāll use it interchangeably with āsensitive dataā: stuff that you want to keep confidential. Whatās so frustrating when breaching confidentiality in logs is the full spectrum of potential impact. In the best case (left) , you might log an isolated, internal credential, like an API key, which (kudos!) you rotate right after fixing the source of leak. The impact is minimal, and you just move on. Of course, all the way on the other end of the spectrum (right) , you might log something that an attacker or inside threat could use to do some real harm . And then somewhere in-between, where I suspect most of the incidents lie. You might log secrets that you unfortunately, canāt rotate yourself. Things like PII or your customerās passwords, which are reused on other sites, because of course they are. And, depending on your policies, threat model, or regulations, you might choose to issue a disclosure or notification. And it is painful. You could be doing so many good data security practices, like secure-by-design frameworks, database and field-level encryption, zero-touch production, access control⦠but logging bypasses all of that⦠and ultimately degrades trust, in your systems and in your company. It feels unfair because itās only a fraction of your security story. And this is a problem that happens to companies of all sizes: Something about āplaintextā just kinda stings, especially as a security practitioner. Itās like⦠the most profane insult you can hurl at a security engineer. Imagine retorting with, āOh yea? Well, you store your passwords in plaintext!ā But logging passwords and storing them in plaintext are⦠kinda the same thing. Because while logs are rarely or purposefully public, theyāre typically afforded broader access than direct access to your databases. Everyone knows by now that storing plaintext secrets in your database is a terrible idea. Logs, however, are still data-at-rest, and we should...