We Masked a Secrets File With a Regex. The Key Printed Anyway.
The output looked fine for about three lines. DATABASE_URL=**** APP_ID=**** PRIVATE_KEY=**** Then it kept going, and the next lines were not masked at all. They were the body of a private key. This is the story of how that happened on Oct 25, 2026, while I was building Since, and why it happened again on Oct 29, after we had written down the rule that was supposed to stop it. 1. A reasonable…
On October 25, 2026, while developing the Since project, a reporter discovered a flaw in a masking system they had set up. The issue arose while trying to list the variables set in a production environment file without revealing their values. The reporter used a regular expression (regex) that masked everything after the equals sign (=) in each line.
However, this approach failed when a private key in PEM format spanned multiple lines. The regex treated the private key as separate lines and only masked the first line, leaving the key's body exposed.
The reporter then wrote down a rule to parse the secrets file and print only the key names and their values, or use a pattern that prints only the names at the start of each line. They believed this rule would prevent any secret leakage. Four days later, on October 29, the same production environment file was used by another agent for a different task. The agent used a line-based command to list the variable names, and once again, the private key's body was printed into the output.
The reporter realized that the rule was not effective because it was written down separately from where it was needed. They also recognized that the grep command they used to implement the rule was not completely safe, as it could misinterpret a line with capital letters and digits as a variable name. To address these issues, the reporter proposed a new solution: using a dotenv parser, which understands the .env file's format and can handle multi-line values correctly.
They suggested that this approach, combined with incorporating the rule directly into the task brief, would ensure that the problem would not recur.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.