Rails World 2026: Hot Cell: Securing Active Storage in the age of AI (Mike Dalessio) Video: https://www.youtube.com/watch?v=swXl8M84YmM Talk page: https://www.rubyevents.org/talks/hot-cell-securing-active-storage-in-the-age-of-ai Unedited machine transcript, generated with Whisper. It contains recognition errors (names, technical terms). Check the video before quoting. ---- Hey, everyone. So the original intention for this talk was to talk about a markdown API for action text. And it was, like, aspirational in nature. It was, like, conference-driven development. Like, I'll get the talk accepted, and then I'll write the code in the meantime. And something strange happened over the year, which was I spent most of my summer heads down working in reactive mode on security issues in Rails. And I worked on that instead of the markdown API because it felt more important and more urgent. And when it came time to prepare the talk, I was like, well, maybe I should give a talk about the thing that's important and urgent. And so instead of an active, instead of a markdown API talk, you're going to hear a security talk. you in advance for your patience. In the beginning, the earth cooled. Dinosaurs roamed the earth. Humans started building things and started writing software. A lot of the software written by humans was not great quality. Some of it had mistakes. Some of it had bugs. Corner cases weren't totally explored. Maybe the design of the software was very trusting in nature. You are here. AI has created all kinds of chaos because AI is really good at finding these problems. And security in particular is really chaotic right now. And I'm a worrier. A lot of what I do is security. And so I worry a lot. And I worry about the future. Morning David talked about maybe it's going to be Terminator, maybe it'll be a more optimistic sci-fi movie. But at this moment right now, I'm very worried. And you should be too. And so I'm going to give you a talk that will get you scared before I equip you to go and be proactive and fix things. So you may say to me, Mike, you worry too much. But I'm saying to you, you're not worried enough. with CVE-2026-66066. Don't read this, by the way. Focus on me right now. Okay. I'll explain it all. When it came time to write this CVE and publish it, I intentionally chose the most opaque, obtuse language I could, and we did not disclose any of the details, because I wanted to buy you time to upgrade Rails. really worried that the nature of this is so bad that there would be attackers immediately going after your systems before you had a chance to upgrade. So I wrote it to be very obtuse. Four sentences. Let's take them one by one. Inversions, prior to blah blah, every Rails version ever. Active storage does not disable the VIPs. So there are some underlined terms here. You're free to read now. to maybe define those terms, it gives me an opportunity to go into exposition mode and explain a little bit about active storage too. If you're not familiar with active storage, it's basically Rails' subsystem for storing images, blobs, whatever you want, and for transforming them. So the typical case is I'm using Lexi, I upload a file, active storage saves it, and then I want to make a thumbnail for my activity feed, a little version of it, and active storage it and does that. And so this CVE is about the second half of this. It's about transforming. And specifically, Rails calls Vips transformer is the class that calls out to libvips on the bottom. Okay. This is the default configuration for Rails. And libvips does something really interesting, which is it outsources the work. Right? The image gets handed to libvips. Libvips looks at it, tries to figure out who should handle it, and routes it to the right library. And some of these libraries you know and love, libping, libjpg, old reliable. Libmagic, maybe a little less reliable. It's got a history of security problems. But there are also libraries that you don't even know about. libmatio. Does anybody know what that library is? Go ahead, shout it out. MATLAB, for all of your MATLAB Rails apps. lib mat io you don't and in fact lib vips don't read this slide either but when I install lib vips on the Ruby slim image this is the dependency list that it installs it's over a hundred libraries and I'm here to tell you that there's no way that those are all secure there are bugs there are vulnerabilities in some of those libraries right now and lib vips has a concept of like library versus untrusted, which is why that sentence I showed you earlier mentioned untrusted libraries. So, like, libmagic and libmad.io are marked as untrusted. But we're starting to get a sense for the shape of the vulnerability now, right? It's like, oh, an image is uploaded that's carefully crafted to try to trick those libraries into doing something. Cool. What are we tricking the library into doing? First, let's talk about who's vulnerable. and you accept image uploads from untrusted users. So this is basically, again, every Rails app uses libvips by default, and every user is an untrusted user. Remember that. Don't trust anybody. So you can exploit the library behavior to read files, read arbitrary files, including environment variables and application secrets. Like, how does that work? Remember, this is all running in a container with your source code, maybe that's sensitive. You have config files, maybe your credentials. You've got your environment variables too. So if you're injecting secrets into your container through environment variables, those are all going to be available to lib mat.io in this case. And the real trick is, what's the exploit? Because you can trick this system into then the thumbnail image that comes back out is going to contain your secrets. And that's pretty scary. I think that's scary. The last sentence is the real impact. Once you have secrets, you can do remote code execution on a server, and you can do what's called lateral movement. And that is like, you have a database secret, you can go mess with the database. You have the Redis login, you can go mess with the cache. And you can maybe even get into corporate networks. I don't know how you guys all have your secrets set up, but this is really bad. This is about as bad as it gets. This is really bad news. This was 9.5 on the CVSS score. About as bad as it gets. But I haven't gotten to the best bit yet. Once we published the CVE, based on this obtuse, opaque information, people reverse engineered this hack in under an hour and published their results on the web. I bought you 60 minutes of time to upgrade. Super scary. Not done yet, though. The other interesting thing about this is that there was actually no big vulnerability here. There were seven small vulnerabilities that got chained together by the agents. I'll run through them real quick so you won't get bored. First of all, active storage direct uploads are enabled by default. They're not anymore. That's been fixed. But it meant that even if you weren't using active storage, that route was still available to attackers. Direct uploads never examine the bytes. Right? Direct upload means it goes from the user's browser to the blob store. And the Rails app never sees it. And so it's forced to trust the content type reported. That's the vector in, is by lying about the content type. Oh, and that's just like a performance thing, right? Like, it would cost you performance if you had to download the file and reanalyze it. Signed variation keys. This one is a little opaque. It makes the attack easier to pull off. And it's not even a security problem. So we're probably never going to change that in Rails. This is the actual fix. We decided to call that block untrusted method. And it's notable that this came out in libvips as a feature that was buried in the change log that you had to opt into the secure behavior. Weird. Libvips, this is the actual flaw. Libvips was fooled by a spoofed MATLAB header. And this was fixed and no CVE was published. wasn't even worth the CVE. libmat.io pointed the finger back at libvips and said, this is functioning as designed. This is not a bug. This is not a security problem. You shouldn't be handing untrusted files to me. Cool. And the last thing was is once you get the secret key, you can use a couple of-- there's a couple of known ways that you can get remote command execution. Based on the secret key, you can escalate that. in the rail security team, but they're all breaking changes to fix, and so we've been dragging our feet. But this is the really bad one, which is once you get the secret, you can then leverage that. So all seven of these were chained together by AIs based on very little information. This should really scare you. They're getting really good at this. If you're not worried yet, here's a video of the exploit script running in real time, pulling out all of my secrets an app. Pretty scary. Once you know what to do, it happens really fast. It should also scare you that these libvips vulnerabilities, sorry, libvips dependencies, so far this year, there have been 378 vulnerabilities published in these dependencies, in libvips or its dependencies. So there's a lot of them, and there's more being reported every day. This is 37 signals, hacker one account data, This is when you have a bounty program, this is what the valid reports are looking like now. This is like going parabolic at this point. Super scary. So there's a whole category of problems here. Like I can fix this one CVE, but like what's going to happen when there's a zero day vulnerability found in the next image processing library? Like we're going to have to go through all of this again. And so this is when I started thinking about how to fix it. You're probably all screaming inside. Fix it, Mike. You're on the security team. Fix it. When I think about fixing it, I think about risk. And how do we decrease risk? And here it's the risk of having a vulnerability in one of those image libraries. And I just covered this territory where we know the probability of finding another vulnerability in these libraries is super high. And probably not going down anytime soon. So we're forced to think about the impact of blast radius. How do we minimize the amount of damage that can be done? if one of these vulnerabilities is found tomorrow. And that's what part two of this talk is about. How do we actually reduce the blast radius? Specifically, the question I want to answer is, how can we run active storage so that it doesn't matter if there's a vulnerable library that's running this untrusted code on an untrusted file? And the solution that you probably all would reach for, just like me, is some kind of a sandbox. We want to make sure this runs somewhere. And so I started thinking about what are the five easy steps-- five easy steps to secure active storage. Step one, let's define the requirements. And this will actually become the prompt that I feed into my agent as we build this system together. So the grab bag of requirements I had is I want it to be a drop-in replacement for Rails. You shouldn't have to make any code changes. It should just be a configuration change. I want to run everything with the least privilege, right? I want it to be a very limited user in a file system that doesn't allow SUID. I want to drop all the capabilities in the Docker container, like least privilege. I don't want it running with the Rails privileges, right? Hard limits on the container. I want to limit CPU time. I want to limit memory. I want to limit file size. I want to limit number of files, number of processes. Let's make it as hard as possible to do damage if there is an exploit. I don't want to give any access to the app file system or the app environment so there are no secrets to exfiltrate. I don't even want there to be a network interface. Because if something happens in that box, I don't even want them to be able to make a network call back out. I don't want them to be able to move laterally within your network. I want it to be disposable, like we're going to start up a process to handle an image, and I want to kill that process when it's done. of that is limited. I want the deployment lifecycle to be very familiar. I want it to be easy to deploy with Kamal or Kubernetes. And I want you to be able to build your own things. Like I built active storage on top of this system, but you should be able to build whatever you want. If you want a secure place to unzip files, you should be able to build that. So this is the requirements list. And I started thinking about real-life analogs to this. And this is a photo from Oak Ridge National which deals a lot with radiation, radioactive materials. And they have a device that they call a hot cell. And basically what it is, is it's a big lead box. And even the window is like mineral oil so the radiation can't get out. And you have to do everything with these little manipulators, right? And anything that comes in or out of that box is tightly controlled. And this is exactly what I want, but for active storage. So this is where the name comes from. And that, by the way, is also item number two. one of the five easy steps to fixing active storage. And this is the system as we can see so far. There's a container and there's something going on, but let's get more specific. How do we jam this into Rails? Now, thankfully, Rails has a config for this already. This is amazing. So there are three different config parameters, each of which controls one aspect of active storage. Analyzing, which gets back metadata, like how many pages are in this PDF. There is a variant processor, which is transformations. It's for rotating or cropping or resizing. And previewers are for generating a thumbnail for non-image files like PDFs or movies. And so really all I want to do here is I want your config change to be like that. I want to be able to go back and forth. That should be all you need to do here. So, we know that now the shape of this is like there's an existing class with an existing API. I can do that. And so, hot cell, the project, is actually five different gems. There's hot cell core, which is the common bits. And then there's client and server on the hot cell level. And this kind of defines how does work get done and how do error codes get returned and some of the communications. And then there's active storage, client and server gems. which subclass, and that's what allows us to do a drop-in replacement for Rails. And so now this is what the system looks like, right, in my head, where we got a hot cell client and a hot cell server, and they have to communicate somehow, and I've kind of hand-waved at this so far, because I said, I don't want a network interface on this, so how do we actually get inputs and outputs working? And the answer is Unix sockets. Unix sockets are great. It's a little file on disk that processes can read read and write to, but it's not routable on the network. It's a very common way to do inter-process communication. And the really interesting bit is send message, the system call, supports passing open file descriptors. And this is really cool. This is like magic. So the way this works is on the left-hand side, the image upload goes in, the hot cell client class opens the file on disk, and then hands the file descriptor over to the hot cell container. is not accessible inside the container, but that file is, because I've given it the handle, and this is what we use for all the inputs and outputs. It's pretty good. But we still don't know how the work is going to get done, and that is step five, how to actually do the work. Unsurprising, it's a supervisor worker style thing, just like Active Job or Puma or anything else that you can think of. Like, this is pretty straightforward and probably not worth spending too much time on. And this is the finished system, and this is the code that's actually running now in production at 37 signals. And I'm here, now that I've scared you, to say to you, you should be running Hot Cell in your apps. And I'm going to tell you how. Rolling it out. Once you've installed the gem, you can just run Hot Cell install. It'll create three files and one empty directory. And that's pretty much it inside of a Hot Cell subdirectory. So the gem file is exactly what you think it's going to be. where you can actually configure hot cell. It's just Ruby code. It's just Ruby code. It's not a Rails process, but it is a Ruby process. And you can set the limits. Some of the things that are available are listed here. I suggest you tune those once you get going, but this is where you do that initial configuration. Those are just global limits, but then we can actually get more refined along the way as well. When you deploy your app, you've got to set up the So the only thing that's shared is a directory with two sockets in it, two Unix sockets in it. You just have to configure that. And you do the same thing in your accessory configuration. I'll break this one down. It's a lot of code. You set up the volumes to match what you have in your application. You set up your Docker container limits. And you set up any of your capabilities that you want to have, too, including network none. which is the proof that none of this actually needs the network to work. The drop-in replacement for Rails is, you know, you could be using any number of these Rails classes on the left, and all you have to do is change your config to use the corresponding twin on the right that's provided by Hotcell. So this is what your typical application configuration would probably look like. Just set the three configs, set the two properties you have for the Unix sockets, and you're good to go. When you configure the hot cell itself, you just have to load the classes. Because remember, this isn't a Rails app, so Zite work does not work here. So you require the classes you need, and you configure them. So here's where you can do per operation configuration. So maybe the cell itself has a deadline of 10 seconds, but you know this operation, you want it to be like two seconds. You can do that kind of configuration here. a kind of a vanilla active action text, active storage application. Like, that's it. You configure active storage, you configure the hot cell, you deploy it. That's it. It also comes with great observability. Even though we can't trust the worker in the container, we don't know if that's been hacked, we can trust the supervisor process, and we can obviously trust your Rails app. And so, we log events in the Rails app, just like it's a database hit. good metrics around that. We periodically pull metrics from the supervisor, things like queue depth that we can't get from the requests. And then the supervisor itself will do a little JSON log to standard out, so you can actually see if children are killed, why were they killed, that kind of information. And you can light up a Grafano screen. This is what we use internally for our dashboard. And I won't go through it all, but you can set up alerting just however you want to do it in your environment. The interesting bit is this only cost us eight milliseconds per call, which is lower than I expected it would be. Still maybe higher than you'd like. We could probably bring that number down. Right now it's related to, I think, garbage collection. But that's pretty cheap to know that you won't be zero-dayed the next time image magic has a problem. It's also very flexible. If you want to have multiple queues, you can just stand up multiple cells on different sockets and have different queue depth and different timeouts and different deadlines. You can have multiple input and output files if you have a custom operation you want to write. You can bring your own container if you work in a corporate environment. There's a conformance test that will tell you whether your container is configured properly to work well. And again, all the per operation limits are totally configurable. If you want to write your own operation, so you have your own thing you want to jam into hot cell, this is what it looks like. It's probably familiar to some of you. I drew heavily from active job. There's a perform method, and the perform method can take whatever arguments you want. So here we see we're giving it a name, operation extract text. We set some default limits that can be overridden, and then the perform method. And to call that from the Rails app, we simply have a thin shim called extract text, and we call perform in hot cell, the same way for a job you would say perform later. Here you can say perform in hot cell and it will serialize the arguments and then bring whatever the file is back. And you'll notice that we have to do a file open on the input and the output because we need to hand a file descriptor, a live file descriptor to the call. But that's really the only hoop you have to jump through. And generally speaking, that's going to be hidden by whatever class you write. So that's kind of how custom operations work. which are both relatively modern apps that use vanilla active storage. This was absolutely no problem. Basecamp was harder. For those of you in the know, Basecamp predates active storage. Active storage was extracted from Basecamp, and we never went back and cleaned it up. So there were a lot of custom operations I had to write. And there's also really heavy usage of attachments. Like, for some reason, our user base loves to send each other memes. Don't ask me. But we had a couple of outages along the way that taught me a lot. And I won't spend too much time on these. Just know that there were outages. And I learned lessons. And I rolled that back into the library. Tuning is something that you should probably allocate time for. But really, this app is ready to go right now. It's not a 1.0 yet because I'm waiting for Rails to ship. I also want to provide some little more observability features. Some syntactic sugar, so to speak. And I may add Linux landlock, if anyone is interested in talking to me about that, I would love to know more. Landlock is a kernel extension that allows you to ratchet down permissions within a process, so that once you've ratcheted it down, there's no way for the process to regain those. So, you could say, I don't want this process to be able to fork exec, and no matter what happens, if an attack takes over that process, it won't be able to regain any of those privileges. That's like a nice like belt in suspenders kind of a thing I'd like to add. Okay. So I scared you. Now I've given you the tools to go and roll out secure active storage in your apps. Now I just want to like reflect for a moment. I started with, oh sorry, it's really easy to do this. Is this QA's fault? And blame it. It's really easy and you would be forgiven for doing that. But I want to have a little bit more view like again earth cooled yada yada yada we're in this time of chaos right now and I think that I'm seeing things trend in a good direction so I want to be optimistic but I also want to give you a call to action like there are things that we need to do to get through this chaos and come out the other side the alternative is I don't know we all quit our jobs turn off our computers and become sheep farmers or something right I want to get through this chaotic period I want you guys to help, and I want the future to be that optimistic future. I don't want Terminator. I want Star Trek. So here are the things that I'm seeing. I showed you this chart before to scare you, but now I'm going to reassure you with it. This is the system working as designed. People are finding vulnerabilities, and they're reporting them. That's great. That's exactly what we want. We know the vulnerabilities are out there. We want them to be reported responsibly, and that's happening. deal with, but it's the system working well. And there's a finite number of vulnerabilities. Right? Right? And at some point, we're going to have the last bug party. We'll have the last vulnerability party. This is unsustainable. It can't go on like this forever. The number has to come back down at some point. When I said 378 vulnerabilities found, what I meant to say was 378 vulnerabilities were fixed. They were fixed. in the right direction. Responsible maintainers, fixing the problems, rolling out software updates. System working as designed. This is great. Building confidence. What can you all do? Here's the thing. I think vulnerability reports should all come with their own agent skills. And so this is actually what I did in response to the CVE. So I published a repo that was extracted from my own work at 37signals to examine our apps and see if we had been exploited. And so you can just point your agent at this repo and at your application, and you can ask it, am I vulnerable? Probably. And you can ask it, was I exploited? And it will actually go through all the active storage database records to tell you if you were exploited. And if you need to rotate your secret key, then you can point it at the Rails guides and say, well, then help me rotate my key. So this is the future, and I think that's going to help us all get through this period of chaos. Attack your own work. hot sell I did this religiously which was adversarial review on almost every commit and Jeremy helped me out with some red teaming where we actually set up agents and told them to break in and they found some gaps this is great so doing this doesn't mean that it's going to be a perfect library but it means that it's going to have fewer problems with it so if we do this on our own software we'll get through this period of chaos faster and Yay! Hot sell, baby. The only way through is that software has to get better or it has to be replaced. That's the only way through this period of chaos. And so I hope that you all will take some of this advice to heart. Don't be too scared. Be proactive and constructive. And the future will be Star Trek, not Terminator. Live long and prosper. And thank you for listening to my talk. *outro music*