Shipkeep is an open-source platform to deploy apps on your own servers. An agent on each server runs containers and routes, and a control plane tells it what to do. Last week the agent learned to ship container logs, and the browser learned to open a shell in a container.
Then a security audit of main filed eleven issues. Three were P1:
- secret values could reach the log store unredacted, in two different ways;
- one WebSocket message, under 64 KiB, could crash the API process. I had written that code the same day, while answering review comments.
I fixed each issue with a test that failed on the old code first. Then I reviewed each fix the way I would review someone else's pull request. Five of the eight fixes had a real bug of their own.
Absence is not "no secrets"
The agent removes secret values from log lines before shipping them. To know which environment variables are secrets, it reads a container label, sk.secret_env, which lists their names. The agent writes that label when it creates a container.
Containers created before the label existed have no label, and the shipper read "no label" as "no secrets". After an agent upgrade, an application that printed its token got that token stored as written.
Worse, a new container with no secrets also had no label: the agent only set it when there was something to list. Missing and empty meant the same thing, so the shipper could not tell an old container from one with nothing to hide.
The fix:
- The label is now always set, empty when there are no secrets.
- A container without the label is treated as one whose secret names are unknown: every environment value of 8 bytes or more is redacted,
PATHandNODE_ENV=productionincluded, until the application is redeployed.
Over-redacting is ugly in logs. Leaking a token is worse.
Logs come one line at a time
The second P1: a secret containing a newline, like a PEM key, was never redacted. Docker output is split into lines before redaction, and the redactor searched each line for the whole value. No single line ever contains a multiline value.
Each line of a multiline value is now a value of its own. Then a related case: lines are cut at 16 KiB. A line cut in the middle of a secret ends with its first half, which no whole-value match finds. So for a cut line, the redactor also masks the longest start of a secret that the line ends with.
My first version ran that cut-start redaction before the normal one. The review found the hole:
TOKEN=abcdefgh_abcdefgh
cut line: ... abcdefgh_abcdefgh
cut-start first: ... abcdefgh_[redacted]
The last 8 bytes of the secret are also its first 8 bytes. The cut-start pass masked them, and the whole-value pass then had nothing left to match. Half the secret shipped.
Running the passes the other way round fails too: a shorter secret inside the cut start hides the rest of it. The version that holds does not chain replacements at all. For each secret, one pass over the line with the Knuth-Morris-Pratt failure function finds every occurrence, overlapping ones included, plus the start the line ends with. Then the union of those spans is redacted:
for _, value := range r.values {
found = value.match(found, line, cut) // every occurrence, and the cut start
}
// sort, merge overlapping spans, replace each with [redacted]
It also makes the cost linear. Secrets can be 64 KiB, and a naive suffix scan of a crafted 16 KiB line is quadratic. A randomized test compares the spans with a byte-by-byte scan on 20,000 cases over a two-letter alphabet, where values overlap themselves and each other.
64 KiB of braces
The browser terminal sends control messages over a WebSocket: {"type":"resize","cols":80,"rows":24}. My code turned each message into a class-validator DTO with plainToInstance, and only then validated its fields.
plainToInstance walks the whole object recursively. A resize message with an extra field nested 3,000 levels deep fits in 64 KiB, and it overflows the stack. A WebSocket message listener runs outside the framework's exception handling, so that RangeError could take down the process, and every session in it.
The fix checks the message's shape before anything transforms it: exactly the expected keys, each a primitive. Each message is also handled inside its own try, so a failure ends only that session.
The review of that fix found a weakness, not one of the five bugs: my try also wrapped the shape check. If the check itself ever threw, the message would be silently dropped instead of ending the session as the spec says. Worse, the tests still passed with the shape check deleted, because the broad catch hid the overflow. Now only JSON.parse is caught there. I checked that deleting the shape check makes three tests fail.
Read, compare, write
GitHub tells Shipkeep when the GitHub App is installed, suspended or removed. An event applies only if it is newer than the last one applied. Two problems:
-
Two deliveries at once. Both read the same row, both pass the time check, and the older one can write last. An older
unsuspendundid a newersuspend. -
A delayed event after a removal. The removal deleted the row, and with it the time of the last event. A delayed
unsuspendthen recreated the installation, active.
Each delivery now takes a transaction-level advisory lock per installation before reading. A removal keeps the row as a tombstone. GitHub gives a reinstalled App a new installation id, so nothing legitimate ever follows a removal.
The test forces the interleaving. A third PostgreSQL connection holds the installation's row while both deliveries start, and releases it once both are waiting. The old code lets the older unsuspend win, and with the fix the newer state stays, in both orders.
The review found what the lock broke. Before the lock, each delivery purged expired delivery records, locking those rows. A delivery waiting for one busy installation kept them locked, so a delivery for any other installation blocked behind it. The purge now uses FOR UPDATE SKIP LOCKED. With the old purge, the new test hangs until its timeout.
Refuse, and ask
Deleting an application after a failed first deployment could free its domain while a server still routed it. The cleanup of the failed deployment was queued but had not run yet. Another application could then claim the hostname.
The first fix refused the deletion until every server had confirmed the cleanup. The review found the dead end. A creation that failed after reaching the server gets no cleanup at all. A cleanup that expires can never be queued again under the same key. Either way, the application could never be deleted.
So a refused deletion now asks: it queues a removal for each container or route a server may still hold, audits that, and answers 409. Once the servers confirm, the next attempt goes through.
Then the automated review on the pull request caught what that change broke. The deletion queued those removals before it looked at the confirmation token. Deleting an application requires a confirmation, and any token, valid or not, could now make a server remove containers. The token is now checked first, without being spent, so it stays usable for the deletion that follows.
What the reviews were for
None of these bugs were in code I hadn't touched. Every one was in a fix: a fix makes an assumption about the bug, and the review checks that assumption. Each fix started with a test that failed on the old code, and that test passed every time. It just did not cover what the fix itself broke.
Reviewing my own fixes cold, a few hours later, caught five of them before merge. The automated review on the pull request caught the sixth: the confirmation token.
Where it stands
- Released:
v0.1.0-alpha.5, with all of the above, on refreshed base images. The release scan, which stops on any high or critical finding that has a fix, passed on both architectures with no exception. - Not
v0.1.0-alpha.4. That release stopped halfway. The workflow pins the image of the tool that copies the control plane image by digest, and quay.io no longer served that digest. The binaries were published, the image and the installer bundle were not. Pinning by digest protects you from an image that changes, not from one that disappears. A published release is never replaced, so alpha.4 now says so at the top, and alpha.5 is the same code plus a one-line fix. - The control plane image still has high findings in Debian packages with no fix yet. The triage checked what the process actually loads: Node carries its own zlib and zstd, and nothing in the container uses PAM, util-linux or Perl. Each one is recorded in
docs/security/image-triage-2026-11.md, with the pinned PostgreSQL image's one high finding, accepted until December 18. - Installing the published alpha.5 from scratch, the way the guide says, still found three things no test had: a documented command without a terminal that stops at a question it did not expect, a misleading error when the agent starts before the control plane is ready, and a restore that leaves a container running. They are #499, #500 and #501.
- One more thing from the release day: GitHub squash-merged a pull request during an API incident, never marked it merged, and never ran CI on the commit. I did not tag that commit. I waited for the next merge, and tagged once CI was green on it.
Where you can help
- You run self-hosted apps: follow the installation guide on a disposable Ubuntu 24.04 VM and tell me where it breaks.
- You like breaking things: the exec WebSocket, the log shipper and the GitHub webhook endpoint are all new. Issues are welcome, and the security policy says how to report privately.
- First contribution: the good first issues each say what to change and when it is done.
And a question for the comments: when you fix a security bug, who reviews the fix?
Top comments (2)
The advisory lock makes the read, compare, and write atomic. Either delivery can still acquire it first, so the result depends on how you define "newer." If you compare sender-generated timestamps with whole-second resolution, a suspend and an unsuspend can tie. A strict
>drops whichever valid event is processed second. With>=, an older event can overwrite a newer one again.The interleaving test controls which delivery gets through first. I'd add a case that gives both events the same timestamp and checks the final state in both processing orders. If the sender guarantees a monotonic ordering key, store that key on the tombstone too. A stable tie-breaker can make the result deterministic, though it only preserves the sender's order if the sender gives that field ordering semantics.
Which field does the "newer" check read?
Good question. The check reads installation.updated_at from GitHub's payload, which has whole-second resolution, so ties do happen.
Ties are decided by a rule, not by arrival order. In changeApplies (a pure function): a newer timestamp applies; at an equal timestamp, only a suspension of an active installation applies; any other change in the same second, a replay included, changes nothing. A removal applies whatever its time, and nothing applies after it.
So a suspend and an unsuspend with the same timestamp end suspended in both orders: unsuspend then suspend applies the suspension, suspend then unsuspend drops the unsuspend.
The cost is the case you describe. If GitHub really did suspend then unsuspend within one second, we keep the installation suspended until its next change. GitHub gives us no ordering key with sequence semantics (the delivery GUID is random), so we can't recover the sender's order on a tie. I chose to fail closed: a wrong "suspended" shows up and clears on the next change, while a wrong "active" would quietly ignore a suspension the owner asked for.
On tests you're right about the gap. The unit tests cover each recorded state at equal times, but no test runs both deliveries through the store in both orders and checks the final row. I'll add that one.