A secret that ran code: post-mortem of a vulnerability in my own secrets manager
On this page
- A line that looked harmless
- Vaultic in two minutes
- The bug: data that turns into code
- Who could exploit it?
- The fix: single quotes
- Why '\''
- The second vector: newlines in $GITHUB_ENV
- The smaller bugs behind it
- 1. Secrets the mask didn't hide
- 2. Private keys readable by other users
- 3. A hash that confirmed passwords
- 4. Half-written files
- Disclosing it
- What I take away
- If you use Vaultic
A line that looked harmless#
I've just published a high-severity security advisory, with a CVSS score of 8.7, against a tool of my own: Vaultic, a team secrets manager written in Rust. The whole bug fit in these lines of version 1.4.2:
"github" => {
if mask {
println!("echo \"::add-mask::{value}\"");
}
println!("echo \"{key}={value}\" >> \"$GITHUB_ENV\"");
}
"gitlab" => {
println!("export {key}=\"{value}\"");
}They look harmless: they print one environment variable per line, with its value in quotes. In fact, it's the same syntax GitHub's documentation shows for setting variables in a workflow. And Vaultic's documentation said to use them like this:
eval "$(vaultic ci export --env prod --format github)"If you already see the problem, you're ahead. If not, this post is for you: we reproduce it with the real binaries, look at who could exploit it and how it was fixed, go through the smaller bugs that turned up behind it, and tell how it was disclosed.
Vaultic in two minutes#
Vaultic comes from something I've seen in almost every team I've worked with: .env files with passwords and API keys passed around over chat or email. Instead, Vaultic encrypts them and keeps them in the repository itself, next to the code, and they travel with Git like any other file. We use it in our team on real projects, with several environments and several people.
The encryption is asymmetric and uses age. Each person has a key pair, and .vaultic/recipients.txt holds the whole team's public keys. On encryption, the content is encrypted once from a random file key (with ChaCha20-Poly1305), and that file key is encrypted separately for each recipient (with X25519). This is the real header of a test .env.enc with two recipients, decoded:
age-encryption.org/v1
-> X25519 NbUtRsMs0VKh++9Kv//IWVvFeUJ5iTlGho2sqk16FDk
bAFsWhFNKwB4LDBTyNokqs9OmctUG0Jumi+knI44RDA
-> X25519 kkSyhB9UFk+741ADe+2W9hjdtWb28EFV07CU70M8LS8
TwSKydQdVI+dESQD4MLWYVeE9YlxlNlJYS7I/KhXQlU
-> g1z8y-grease
XbknbG4IWhrYPriLmcTaFVwMvfxf+QUsHqmJ7ChzBu5L+bpnM8TXMYlrmjjZAQg8
fjmtUZv7FXVkhf9Rrd4DeWp8ke7o+PzF00vH2IXW
--- XKQxc+r/6LZzS3RE…Each -> X25519 block is the file key encrypted for one person: whoever decrypts finds theirs and opens it with their private key. The third one, grease, is random padding the age library adds on purpose, so that programs reading the format get used to ignoring recipient types they don't know. The encrypted content starts after the --- line.
This gives a property that matters for the rest of the story: public keys aren't secret. A public key can only encrypt, never decrypt, so keeping them in the repository is safe. It's like a mailbox slot: anyone can drop a letter in, but only whoever has the key can read it. Keep that in mind: anyone can drop a letter in.
The bug: data that turns into code#
vaultic ci export decrypts an environment inside a CI pipeline and prints it as shell commands, so that eval runs them and the variables get set. The problem is that inside double quotes the shell still interprets things: $VARIABLE, $(command), backticks and backslashes. A secret's value stopped being data and became code.
To check it, I built 1.4.2 and 1.4.3 from their tags in the repository and encrypted a test environment with these two values:
DB_PASSWORD=Kx9$$fT2w
API_TOKEN=tok_$(echo " [!] this just ran" >&2)This is what 1.4.2 printed with --format gitlab:
export DB_PASSWORD="Kx9$$fT2w"
export API_TOKEN="tok_$(echo " [!] this just ran" >&2)"And this script loads the secrets the way the docs said, first with one version and then with the other:
#!/bin/sh
# sh load.sh (with vaultic-1.4.2 and vaultic-1.4.3 in the same folder)
# Load the secrets the way the docs said, with each version
for v in 1.4.2 1.4.3; do
echo "--- vaultic $v"
eval "$(./vaultic-$v -q ci export --env dev --format gitlab)"
echo "DB_PASSWORD=$DB_PASSWORD"
echo "API_TOKEN=$API_TOKEN"
doneThis is the real output on my machine, with Git Bash's sh on Windows 11:
--- vaultic 1.4.2
[!] this just ran
DB_PASSWORD=Kx922542fT2w
API_TOKEN=tok_
--- vaultic 1.4.3
DB_PASSWORD=Kx9$$fT2w
API_TOKEN=tok_$(echo " [!] this just ran" >&2)With 1.4.2 two things happen, and both are bad:
- The value of
API_TOKENruns. Here it only prints a warning, but it could be any command, and it would run on the runner with the job's permissions, with access to all its secrets and tokens. - The password gets corrupted with nobody attacking anything.
$$is a special shell variable, the process PID, soKx9$$fT2wbecomesKx922542fT2w. And generated passwords contain$, quotes and backslashes all the time.
A third case came up in my tests: with a stray backtick in a password, the whole eval fails with a syntax error and none of the environment's secrets get loaded.
With 1.4.3, the values arrive intact, whatever they contain.
Vaultic is written in Rust and, as we covered in Why Rust remains the safest language in 2026, Rust removes whole classes of memory bugs. But this isn't a memory bug, it's a bug of meaning: no compiler knows a String is going to end up inside a shell.
Who could exploit it?#
Here's where the mailbox comes back. Putting a malicious value into a .env.enc needs no private key at all: the public keys are enough, and they're in the repository. So anyone who could get a modified .vaultic/*.env.enc into a branch whose CI job runs vaultic ci export with the private key (in the VAULTIC_AGE_KEY variable) could run code in that job.
And there's an aggravating factor: an encrypted file can't be reviewed. In a pull request, a change to dev.env.enc is a block of base64 that changes entirely. The reviewer sees that the secrets were updated, not a $(...) hidden inside.
Anyone who could change an encrypted file in a branch with CI could run code in that CI, without holding any private key and without the pull request review showing it.
The advisory's CVSS vector sums it up:
CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:NMetric by metric:
| Metric | Value | Why |
|---|---|---|
| Attack vector | Network (AV:N) | Pushing a change to a remote repository is enough |
| Complexity | Low (AC:L) | A $(...) in a value, no special conditions |
| Privileges | High (PR:H) | You need to be able to modify files in a branch that runs CI with the key |
| Interaction | None (UI:N) | The pipeline runs on its own |
| Scope | Changed (S:C) | The bug is in Vaultic, but the damage lands on the CI runner and everything its credentials reach |
| Impact | C:H/I:H/A:N | Full confidentiality and integrity inside the job; availability isn't the goal |
PR:H is what keeps it from being critical: not just anyone can exploit it from outside. S:C is what pushes it so high: the one running the code is no longer Vaultic, it's your CI infrastructure.
The fix: single quotes#
Inside single quotes, a POSIX shell expands nothing: no variables, no commands, no backslashes. The only character to handle is the single quote itself, which is closed, escaped and reopened. This is the fix's entire function:
/// Quote `s` for POSIX shells. Inside single quotes nothing is expanded,
/// so the only character to handle is the single quote itself.
fn shell_quote(s: &str) -> String {
format!("'{}'", s.replace('\'', r"'\''"))
}With it, --format gitlab prints export API_TOKEN='tok_$(...)', and --format github switches to printf instead of echo:
printf '%s\n' 'API_KEY=secret123' >> "$GITHUB_ENV"printf '%s\n' prints its argument as is. echo isn't that predictable: depending on the shell, it interprets backslashes or treats a -n as an option.
Why '\''#
The most cryptic part of the fix is turning each ' into '\''. Inside single quotes nothing can be escaped, not even another single quote, so the trick is to step out of them for a moment. A value like it's becomes 'it'\''s', which the shell reads as three pieces glued together:
'it': text in single quotes.\': an escaped single quote, outside the quotes.'s': more text in single quotes.
The shell joins words written together without spaces, so the result is exactly it's. And at no point is there text outside the quotes, except that escaped quote, which can't do anything. The fix's shell_quote_escapes_single_quotes test checks this case with a'b.
On top of that, with github and gitlab variable names must be valid shell identifiers; otherwise the export fails before printing anything. And what I like most about the fix is its tests: they don't compare strings, they actually run the generated script with sh and check that nothing was executed:
#[cfg(unix)]
#[test]
fn github_does_not_execute_command_substitution() {
let value = "p@$(echo PWNED)`echo PWNED2`\"'\\";
let (env, stdout) = run_github_script(&format_github("PASS", value, false));
assert_eq!(env, format!("PASS={value}\n"));
assert!(!stdout.contains("PWNED"));
}If a piece of data ends up inside something that gets interpreted, whether SQL, HTML or a shell, it needs that language's exact escaping. And if you can, don't generate code at all: pass the data through a channel that is never interpreted.
The second vector: newlines in $GITHUB_ENV#
$GITHUB_ENV is a file the GitHub runner reads line by line: each NAME=value sets a variable for the job's next steps. If a value contained a newline, whatever comes after it would be read as another variable. And some variables are dangerous on their own: LD_PRELOAD makes every process load a library, and BASH_ENV makes every Bash script run a file first. (NODE_OPTIONS would be another, but the GitHub runner already rejects it in $GITHUB_ENV.)
Today Vaultic's .env parser reads line by line, so a value can't carry a real newline. But the output format mustn't depend on that: the roadmap includes YAML and JSON parsers, which do allow multi-line values. For those values GitHub defines its own syntax, NAME<<DELIMITER, and its documentation warns that the delimiter must not appear as a line within the value. Version 1.4.3 guarantees it by construction:
fn github_delimiter(value: &str) -> String {
use sha2::{Digest, Sha256};
let hash = format!("{:x}", Sha256::digest(value.as_bytes()));
let mut delim = format!("VAULTIC_EOF_{}", &hash[..16]);
while value.lines().any(|l| l == delim) {
delim.push('_');
}
delim
}The delimiter comes from the hash of the value itself and, if it still showed up as a line, it grows until it no longer does. A value can't close the block early.
The smaller bugs behind it#
An injection bug rarely travels alone. Reviewing the rest of the paths secrets go through turned up four more, of lower severity, that 1.4.3 also fixes.
1. Secrets the mask didn't hide#
--mask emits ::add-mask::value, which asks the GitHub runner to hide that value in the logs. But the runner decodes %25, %0D and %0A in its commands' data, as its ActionCommand.cs shows. A secret literally containing %0A was registered with a different value, and the original showed up in clear in the log. The fix escapes % as %25 before sending it.
The same runner has another quirk: it reads each step's output with .NET's ReadLine, which also splits on a lone \r. A secret with a \r inside reached the log split across two lines, and the mask for the full value matched neither. Now each piece is masked separately.
2. Private keys readable by other users#
Private keys were written with the umask's default permissions, usually 0644: readable by any user on the machine. Now they're created with 0600, inside a 0700 directory, like decrypted .env files. And vaultic status warns when your key's permissions are too open, with the same check ssh applies.
3. A hash that confirmed passwords#
The audit log, audit.log, is committed with the repository and holds no values, only metadata. But on decryption, 1.4.2 stored the SHA-256 of the decrypted file. A hash can't be reversed, but it can be checked: if you guess the content, you compute its hash and compare. And a .env file's content is very guessable, because the variable names are in .env.template and many values are predictable. This is the real entry 1.4.2 left in my test environment, with a test git identity, without the date and formatted for reading:
{
"author": "Ana",
"email": "ana@example.com",
"action": "decrypt",
"files": ["prod.env.enc"],
"detail": "2 variables decrypted to .env",
"state_hash": "60d0ff82284ff8a044f0486f168f11fcf4c4efa7207a09bf5326e46318529951"
}And this script, which only uses that hash, confirms the password without decrypting anything:
#!/bin/sh
# sh guess.sh (in the project root, after decrypting with 1.4.2)
# The hash 1.4.2 left in audit.log on decrypt (the log is committed)
target=$(tail -1 .vaultic/audit.log | sed 's/.*"state_hash":"\([0-9a-f]*\)".*/\1/')
# The keys come from .env.template; only the password is unknown
for guess in 123456 password winter2024 summer2024 qwerty; do
h=$(printf 'PORT=5432\nDB_PASSWORD=%s\n' "$guess" | sha256sum | cut -d' ' -f1)
[ "$h" = "$target" ] && echo "confirmed: DB_PASSWORD=$guess" && exit
done
echo "no match"And its real output:
confirmed: DB_PASSWORD=summer2024With a weak password a dictionary is enough; with a strong random one there's nothing to be done. But a secrets tool shouldn't hand out an oracle for checking guesses. Version 1.4.3 stores the hash of the encrypted file, which still works for detecting tampering and says nothing about the content.
4. Half-written files#
If encrypt --all was interrupted halfway through writing a .enc, the file could be left truncated. Now everything is written atomically: first to a temporary file in the same directory, which is synced to disk and then renamed over the original. A crash leaves the old file or the new one, never half of one.
Disclosing it#
Fixing it isn't enough: whoever runs a vulnerable version has to find out. These were the steps:
- Version 1.4.3, with binaries verifiable through SHA256 and a minisign signature, also published on crates.io.
- A GitHub security advisory, GHSA-5cfx-fmm5-7p2f, with the impact, the affected versions (1.4.0 to 1.4.2; 1.3.0 didn't have
ci exportyet), the fix and workarounds for anyone who can't upgrade yet. Once GitHub reviews it, it goes into its public advisory database, which tools like Dependabot draw from. - A CVE, requested from GitHub, which is a CVE numbering authority. It's under review; I'll add the number here once it's assigned.
- RustSec, the Rust ecosystem's advisory database that
cargo auditqueries. I prepared the advisory in their format and validated it with their own linter before submitting it, but a maintainer closed the PR: Vaultic doesn't meet their minimum popularity, with 29 recent downloads. The advisory was correct; the rule is theirs, and it makes sense for a database maintained by volunteers. The practical consequence is thatcargo auditwon't warn about this bug, so the channels that count are the GitHub advisory and the release notes.
The same release updates rustls, used by the update check, for five RustSec advisories. And the repository now runs cargo audit every week and whenever the dependencies change.
What I take away#
- Never put data inside code someone else will run. If a value ends up inside something that gets interpreted, it needs that language's exact escaping. For a POSIX shell, single quotes.
- Documenting
evalis a strong promise. If your tool generates code for the user to run, that output is attack surface and deserves tests that actually run it. - Encrypted content doesn't review itself. Treat changes to
.vaultic/as code changes: require review, for example with CODEOWNERS, and have someone with a key decrypt and compare them before approving. Whoever controls a job's secrets controls its environment. - Removing a key doesn't erase the past. When someone leaves the team,
vaultic keys removeandencrypt --allprotect the new versions, but the old ones are still in the Git history, encrypted for their key too. You have to rotate the values: passwords, tokens and API keys. - A secret's hash is an oracle. If you need to detect changes, hash the ciphertext, or use an HMAC with a key that isn't in the repository.
- Disclose even if your project is small. The public advisory is what lets each user know whether they're affected and what to do.
Vaultic is a small project: as of today it has 145 downloads on crates.io. Even so, the bug was real, with a clear path to running code in a CI. And it wasn't in the cryptography, which is the part that gets the most care, but in a line that formatted text. In any tool that generates scripts, that's the first place to look: the exact point where data turns into code.
If you use Vaultic#
Upgrade:
vaultic update # or: cargo install vaultic --forceIf you can't yet, don't use eval with --format github or --format gitlab. Use vaultic ci export --format generic > .env or vaultic decrypt --env <env> --stdout with a .env loader that doesn't run code, and review recent changes to .vaultic/*.env.enc made by people who shouldn't control your CI.
References
- GHSA-5cfx-fmm5-7p2f: Command injection in vaultic ci export through secret valuesGitHub · github.com
- Vaultic v1.4.3 (release notes)GitHub · github.com
- fix: security hardening for v1.4.3 (pull request #7)GitHub · github.com
- Workflow commands for GitHub ActionsGitHub Docs · docs.github.com
- actions/runner: ActionCommand.csGitHub · github.com
- The age file formatC2SP · github.com
- Shell Command Language (POSIX.1-2024), 2.2 QuotingThe Open Group · pubs.opengroup.org
- CWE-78: Improper Neutralization of Special Elements used in an OS CommandMITRE · cwe.mitre.org
- CWE-93: Improper Neutralization of CRLF SequencesMITRE · cwe.mitre.org
- CVSS v3.1 Specification DocumentFIRST · first.org
- Keeping your GitHub Actions and workflows secure Part 2: Untrusted inputGitHub Security Lab · securitylab.github.com
Share
Want a security review of your tool or pipeline?
I review code, CI/CD pipelines and secrets handling to find bugs like the ones in this post before they reach production, and help you fix them.
Let's talk→
Comments
Commenting requires a GitHub account. Comments live in GitHub Discussions (SoftDryzz/blog-comments) and are moderated: no promotional links.