Skip to content
Race condition Write-up Intermediate

Securing the Build: A Deep Dive into a Symlink Race Condition in

A helper script in the distroless repository wrote configuration data to a fixed, predictable path in the shared /tmp directory. A local attacker could pre-create a symbolic link at that path so the script overwrote an arbitrary file, such as the system password file.

Anandppatil Follow

Published on medium.com

In the world of cloud-native security, Distroless images are the gold standard. By removing everything — shells, package managers, and standard utilities — they drastically reduce the attack surface of containers.

Anandppatil, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The script used a hardcoded, predictable temporary file path in a world-writable directory without checking ownership or creating the file safely.

Impact

An attacker with local access to a shared build server or CI/CD runner could overwrite sensitive system files, potentially disrupting builds or escalating privileges.

What the attacker needed

Local access to the build machine; ability to create files in /tmp; script runs with higher privileges

The fix

The script should create its temporary file with mktemp, which gives a unique unpredictable name and owner-only permissions, and clean it up on exit.

How it was found

  1. Create a victim file in the shared temporary directory.
  2. Create a symbolic link at the predictable configuration path pointing to the victim file.
  3. Run the vulnerable diff script.
  4. Observe that the victim file's contents were replaced by the script's JSON output.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A symbolic link is a shortcut that points to another file. The build script always wrote its temporary data to the same name in a shared folder, so someone else on the same machine could put a shortcut there first. When the script wrote its data, it followed the shortcut and damaged a file the attacker chose.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.