BlogArchitecture

How AI keys were stolen from Railway, and what your SaaS should copy

A shared build, a credential on disk and a misconfigured permission ended in about $740,000 of unauthorized spend. What I'd copy from Railway's report.

Ink and watercolor illustration: a chain of five keys, each larger than the last, runs from a crack in a wooden crate to the lock of an open teal safe.

If your SaaS stores your customers’ API keys, Railway’s report from 10 November is the checklist for this week. An attacker broke out of a shared build, chained credentials until they could decrypt environment variables, and walked away with AI provider keys that, according to Railway, ran up an estimated $740,000 in unauthorized usage.

What happened

Railway is a deployment platform: you give it your repository and your environment variables, and it builds and runs your app. The final report walks through the attack step by step. In short:

  1. The shared build. Several customers’ builds ran on the same virtual machine. On 20 October at 07:28 UTC, the attacker used a previously unknown vulnerability to partially escape filesystem isolation and read the host’s disk. A credential that builds use to reach internal systems was sitting there.
  2. One credential too many. It was meant for pushing images, but the internal Temporal cluster (the workflow engine behind builds) “accepted it as a trusted client”. With it, the attacker read 353 build histories, variables included, between 13:50 and 15:30 UTC, and took a copy of Railway’s internal monorepo.
  3. The misconfigured permission. Railway replaced that credential at 17:28 UTC, but the attacker already had the code. In it they found an OIDC binding (the mechanism that hands out temporary cloud credentials) defined by mistake. At 03:26 UTC on 21 October they used it to get a short-lived credential.
  4. The long-lived credentials. That got them two long-lived credentials, including an SSH key used by the deployment system. They logged into the machine that orchestrates the fleet and found a credential on disk that could decrypt customer variables.
  5. The search. Between 04:07 and 05:21 UTC they queried the database with regular expressions on variable names, looking for AI provider keys, and decrypted part of what they pulled using the cloud key service.

At 07:14 UTC Railway disabled every cloud credential and the decryption service, and by 09:24 UTC the attacker was out.

The numbers: at most 1.85% of workspaces, about 100,000, could have had any variable decrypted (an upper bound, because the logs identify environments, not individual variables). Linked-account tokens for 1,852 users were decrypted, and Railway reset all of them. To kill the stolen keys, it asked GitHub, GitLab, Anthropic, OpenAI, OpenRouter, SpaceXSI, Google and Stripe to revoke them: “we provided hashes of every key we held to isolate blast radius as quickly as possible”.

Why it matters even if you don’t use Railway

The attacker was after spendable balance. In Railway’s words: “Our internal forensic investigation suggests AI provider keys were the primary target of the attack”. An OpenAI or Anthropic key turns into money within minutes, and the bill goes to your customer.

If your product keeps each customer’s AI key (plenty of “bring your own key” SaaS products do), you are the same kind of target at a smaller scale. And apart from the first step, nothing in this attack was exotic. The rest was credentials with more permissions than they needed and secrets stored on disk.

What I’d copy from their fixes

Railway published what it changed. From that list, these are the four pieces I’d bring to a small SaaS:

  • A throwaway environment for every run of someone else’s code. Railway: “Each build now gets a dedicated ephemeral virtual machine”, with a credential that can only push one specific image. If you run your customers’ code or templates, each run should die when it finishes and see nothing else.
  • One service that decrypts. No service other than the secrets service can now reach the keys that decrypt, and each caller can only decrypt what it needs.
  • Every decryption logged. “All encrypt and decrypt operations are now centrally audit logged”. If you can’t tell who decrypted what and when, you won’t know which customers to warn.
  • Short-lived credentials. Wherever possible, Railway now uses narrowly scoped credentials issued just in time. A credential that expires in an hour is worth far less to someone else.

How I’d do it on AWS

On AWS, KMS (the key management service) covers most of this with encryption context: a key-value pair that is required to decrypt and is recorded in CloudTrail on every operation.

  1. Encrypt each customer’s key with their ID as context:
aws kms encrypt \
  --key-id alias/customer-secrets \
  --plaintext fileb://customer-key.txt \
  --encryption-context tenant=customer-123
  1. Grant decrypt only to the role of the service that calls the AI provider, and only with a tenant context:
{
  "Effect": "Allow",
  "Action": "kms:Decrypt",
  "Resource": "arn:aws:kms:eu-west-1:<account>:key/<key-id>",
  "Condition": {
    "StringLike": { "kms:EncryptionContext:tenant": "customer-*" }
  }
}
  1. Set up a CloudTrail alarm for any Decrypt on that key coming from a different role. With that in place, the alert fires on the first unusual decryption, not the next day.

  2. No long-lived credentials on disk: IAM roles for functions and containers, and Session Manager instead of shared SSH keys.

My take

Your customers’ AI keys are now the most profitable secret you hold, more than a database password. My rule for a SaaS that stores them: stealing one internal credential must not be enough to decrypt them, and every decryption must leave a trace.

I appreciate that Railway published the report with timestamps, numbers and its own mistakes, including a correction to its preliminary report about when decryption started. Also that it is covering the cost of the stolen Anthropic and OpenRouter keys.

What we don’t know yet: the vulnerability behind the first step, which Railway is disclosing in coordination with the affected projects, and who is behind the attack. That’s why I focus on the four steps after it: those are the ones that depend on you.

Sources

If you build a SaaS and want to see how I handle customer secrets on AWS, follow me on LinkedIn.

← All articles

Have a product to build or a tech stack to put in order?

Tell me what you are trying to achieve and where you are today. I reply personally, usually within a day.

Free · 30 minutes

Digital strategy session

30 minutes to map where to start digitalizing and transforming your business. You pay nothing, before or after.

When you book, you answer three short questions: what you need, what stage your project is at and when. That way the session starts with context.