KO
HomePost

The Railway Breach, and What I Learned

2026-11-29

A Railway security breach exposed environment variables and led to CA$2,877 in unauthorized Gemini API usage in a single day. How rotating keys caused a four-day outage, and what I learned.

On October 21 at 23:56 UTC, I received an email from Railway. In Korea, where I was visiting at the time, it was 8:56 AM on October 22. The subject line read: "Urgent: Railway Security Disclosure - Rotate Credentials."

Translator Pro is a service that translates PDF books. I hosted both its translation worker and real-time editor server on Railway. The email warned that an unauthorized third party might have accessed encrypted environment variables—and possibly decrypted some of them. Those environment variables held our Gemini, OpenAI, and Mistral API keys, database credentials, and file storage keys.

I was visiting Korea at the time. And I did not rotate the keys right away.

This is the record of the week that followed. Looking back, the outage I caused while responding to the breach kept the service down far longer than the breach itself. The story of trying to recover the unauthorized charges from Google and Railway—and the fallout a month later—is in Part 2.

If I had to reduce everything I learned to a single rule, it would be this: always put a reasonable spending limit on any pay-as-you-go API key.

What Actually Happened, According to the Final Report

At the time of the incident, all I had was that one disclosure email. Later, Railway's final incident report laid out the full timeline (all times UTC):

  • October 20, 07:28: The attacker broke out of build isolation. Railway detected the intrusion at 13:58.
  • October 21, 04:42–05:14 and 06:36–07:15: The attacker decrypted a subset of customer environment variables.
  • October 21, 09:24: Railway evicted the attacker and, starting at 09:25, began requesting key revocations from AI providers.
  • October 21, 23:56: Our disclosure email arrived—about 17 hours after the decryption and roughly 34 hours after Railway first detected the intrusion.

According to the final report, variables in up to 1.85% of workspaces (around 100,000) may have been decrypted. Because logs only tracked access at the environment level, Railway could not determine which specific variables were taken. On October 23, Railway sent a follow-up email confirming that variables in our workspace matched the attacker's search pattern.

The attacker targeted AI keys by variable name. Railway believes the stolen keys were likely sold for model distillation (the report also cited Wiz's analysis), and estimated total unauthorized spend across affected customers at roughly US$740,000. There was no evidence of access to customer databases.

15 Hours Later, 16,000 Requests in a Day

Roughly 15 hours after the disclosure email, on October 22 at 14:49 UTC (11:49 PM KST), Google sent an anomalous usage alert. Requests were pouring through the Gemini API key stored in our worker.

In a single day, the key saw roughly 16,000 requests (about 15,000 requests and 160 million tokens by Pacific Time aggregation). Our service only ever called gemini-3.1-flash-lite, yet the traffic hit models we had never touched: Gemini 4 Argon, Gemini 3.8/3.6/3 Flash, 3.5 Flash Lite, 3.1 Pro, plus image and TTS models.

Over the next seven hours, the emails kept coming. It was the middle of the night in Korea.

  1. A notice that our usage tier had been automatically upgraded
  2. Three automatic card charges: CA$200, CA$100, and CA$500 (CA$800 total)
  3. A warning that we had reached 80% of our monthly spending limit
  4. A notice that Gemini API access had been paused after hitting the spending limit

In the end, it was not me who stopped the attack—it was Google's spending cap. Usage for the day totaled CA$2,877.08. Even after Google's automatic discounts, the billed amount was CA$1,516.61 plus tax.

The attack ran overnight in Korea, from 11:49 PM to 7:16 AM the next morning. I was asleep the entire time. When I woke up, my inbox was full of alerts, and Gemini had already stopped itself at the cap.

I Rotated the Keys, and Translation Stopped

Starting on October 23 at 00:34 UTC, I spent about an hour rotating every secret stored in Railway (with a single write-only analytics key as the lone exception). I issued new AI keys, created a new database user and deleted the old one, and rotated our storage keys and internal server auth secrets. That was roughly 24.5 hours after Railway's disclosure email.

Then came the second problem.

Our original Gemini billing account had already maxed out its monthly spending limit from the abuse. Because the limit applies at the billing-account level, no key tied to that account could make requests until November 1. So I generated a new key in a project under a different Google account. That billing account used prepaid billing—and its balance was zero. Every request made with the new key failed with 402 Payment Required.

I did have a fallback configured to switch to OpenAI if the primary engine failed. The catch was that our OpenAI balance had been negative since August. Auto-recharge was turned on, yet it had not triggered once in two months. The fallback was already dead, and nobody knew.

The new key was valid. There was no sign it had been compromised. Yet not a single translation went through.

Four Days Without Anyone Knowing

October 24 and 25 saw almost no translation requests. Traffic picked back up on October 26, and over two days, all 147 requests failed.

Of those 147 requests, 142 came from a single customer. They had just upgraded to a paid plan right after their free trial ended, and from the moment they paid, not one translation succeeded. With no clear explanation, they had no choice but to keep retrying.

We had nothing alerting us to failures. Admin notifications were only wired up for payments, translation reports, and sign-ups. Worse still, the worker logged jobs as "completed" even when translations inside them failed. Even if I had been watching the logs, it would have been easy to miss.

I did not realize translations were broken until October 27.

Four Key Swaps Later, Service Returned

On October 27 alone, I swapped the worker's Gemini key four times.

  • The first replacement key belonged to the same zero-balance prepaid account. Naturally, it kept returning 402.
  • The second replacement belonged to the original billing account whose monthly spending limit was already full. This time it came back with 429 errors saying the billing account had exceeded its monthly limit.
  • Only after topping up the prepaid account and switching back to its key did the first translation succeed, at 7:55 PM KST.

The root cause had been sitting in the error messages the whole time. 402 meant no prepaid balance; 429 meant the spending cap was full. Swapping keys could not fix a billing problem.

Smart translation came back online, but image translation did not. Image translation relied exclusively on OpenAI, and as of October 27 the OpenAI balance issue was still unresolved. Worse, when image translation failed, the job still reported "completed" and quietly dropped the images. I only discovered that by running tests during recovery.

Secrets That Looked Unchanged Even After Rotation

While auditing the secret rotation after the incident, I had one more scare. Railway's activity log showed no update history for the worker's database credentials, storage keys, or inter-service secrets. For a moment, I thought the leaked values were still live.

It turned out those variables on the worker were Railway reference variables pointing to the real-time server. Updating the source service automatically updated the worker, too, but the change history was only recorded on the source service. The old database user had already been deleted, and the worker was connecting with the new one.

I had done the audit and still nearly misread the results. With Railway reference variables, you rotate at the source—and audit at the source.

What I Learned

I could not have prevented the Railway breach itself. But the size of the financial damage—and almost the entire four-day outage afterward—could have been reduced or avoided ahead of time.

Always Put a Reasonable Spending Limit on Pay-as-You-Go Keys

This is the biggest lesson. Keys can leak at any time. When they do, what bounds the damage is not the key—it is the limit. What stopped the abuse at CA$2,877 was not me; it was the spending cap Google had in place. Had that cap been lower, the bill would have been lower too.

Prepaying a fixed balance with auto-recharge turned off is also worth considering. Even if a key leaks, you cannot lose more than what is loaded. Relying too heavily on manual top-ups has its own downside, though—the moment the balance hits zero, your service stops, just like mine did.

The real task is picking the right threshold: low enough that an incident will not hurt badly, yet high enough not to interrupt normal traffic.

Other Lessons

  1. Rotate keys the day a security disclosure arrives. The most expensive mistake here was waiting 24.5 hours. The abuse happened right inside that window.
  2. Route billing alerts to your phone. Anomaly warnings, card receipts, and spending-limit alerts arrived all night, but every single one sat quietly in email.
  3. Keep your fallback on a separately billed provider, and actually test it daily. A fallback you never verify is no fallback at all.
  4. Create one key per deployment target, and name it so you know where it lives. During the incident, I could not immediately tell which key belonged to which billing account.
  5. Alert on translation failure rates and provider billing errors. A paying customer retried 142 times while we knew nothing.

As for who pays the CA$2,877 racked up on the stolen key—and what happened over the next month of back-and-forth with Google and Railway—that continues in Part 2: CA$2,877 Spent on a Stolen API Key: Who Pays?.