12255 shaares
293 private links
293 private links
The problem is annoying and difficult. Also secrets can be easy to rotate, can not rotate or ones that attackers use.
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 happens to companies of all sizes: X, Google Cloud, Facebook
Causes:
- Direct logging
- Kitchen sinks: objects that contain or hold secrets, often in opaque or unexpected ways. Errors of requests are examples.
- Configuration changes: turning logging level to debug.
- Embedded secrets: a token shared by URL
- Telemetry: error monitoring and analytics are logs. They often provide the local variable context.
- User Input: the user provides wrong but PII data in a wrong field for example.
Fixes:
- Data architecture:part of the solution is reducing the number of data flows and shrinking the problem space so you simply have less things to worry about and protect. One logging utility!
- Data transformation: minimization, redaction, tokenization (and the trolls: hashing, encryption, masking)
- Domain primitives: “combines secure constructs and value objects to define the smallest building block of a domain”.
new Secret("..."). They provide security invariants and guarantees that basic string primitives simply cannot. - Compile-time: a logging function that never accepts secrets (TS branded types helps!)
- Run-time classes (
extends String): it identifies the secrets. Overwrite thetoString()method in JS to return[redacted]but an explicitunwrap()method for example. - Read-once objects: they throw an error or
[redacted]in case of second read. - Taint checking: the general idea here is that you add taint to various sources (like database objects), and yell loudly if the data flows into certain sinks (like logs). Demo: https://semgrep.dev/playground/s/4bq5L It's awesome and not awesome as the same time.
- Log formatters: redact known dangerous property names
- Unit tests
- Sensitive data scanner
- Sampling (every cases instead of proportions)
- Log pre-processors such as Vector
- People
Strategy:
- Lay the foundation: Developing expectations, culture, and support is a must-have. Define what a secret is. Use structured logs to allow operations on them.
- Understand the data flow: with the foundation laid, the next best thing to do is to understand and chart out how secrets flow through your system.
- Protect at chokepoints: CI/CD and App code first, before relying on the loggging library and other operation services.
- Apply defense-in-depth: data transformation, read-once objects, log formatters in the library, log pre-processors, sensitive scanners, people
- Plan for response and recovery