On 25 July 2026, researchers from HacktronAI achieved remote code execution (RCE) and administrative access on the Discourse web application deployed at community.openai.com. The attack used the image upload feature, where HEIF/AVIF files were processed by ImageMagick and libheif, which contained a previously unknown memory corruption vulnerability.
They then moved laterally by abusing the site's Sign in with OpenAI SSO feature and hijacking the ChatGPT account of an OpenAI engineer. From there, they accessed OpenAI's private GitHub repositories through a previously connected Codex account and reported their findings through the bug bounty program.
Using similar vulnerabilities, they also found weaknesses in Slack, Meta, Next.js, GitHub Enterprise, and other systems. Exploitation against WordPress may also be possible.
If a real threat actor carried out this exploitation chain, the consequences could be catastrophic.
How can we build defenses against RCE in web applications without depending entirely on updates or the security of code components we may not control?
RCE defense in web applications beyond security testing

The most direct way to fix an RCE is to close the attack vector by fixing the vulnerable code or updating the affected component. But what if we do not know which part is vulnerable?
Most efforts have historically focused on security testing first-party and third-party code to identify and close possible weaknesses, with the hope that nobody exploits them before a fix becomes available.
AI, agent capabilities, and harness engineering are becoming increasingly sophisticated and can now perform security assessments better than most human security testers. AI still cannot guarantee that every vulnerability and exploitation path will be identified, especially in supply-chain cases such as OpenAI and Discourse.
Vendors and organizations worldwide have tried to implement several defensive options.
- WAF. It is generally useful only for blocking generic payloads or specific payloads that are already known. A deny-by-default approach using application contracts is interesting, but payloads that still conform to the contract, such as image uploads or valid parameters, can pass through.
- Intrusion Detection/Prevention System. This provides detection at the host or network layer. Vendors sell it under various names, including IDS, IPS, EDR, CDR, CWP, and others. Its effectiveness depends on rules and behavioral analysis.
- Runtime Application Self-Protection. This is usually implemented by instrumenting and hooking dangerous functions, such as file or shell operations. It requires comprehensive rules while keeping performance impact from becoming disruptive.
- Sandboxing. This can operate at the application or system level. Capabilities such as syscalls or specific system operations, including network and file access, are reduced or wrapped with additional protections.
- Specialized architecture. This avoids general-purpose systems in favor of genuinely minimal and purpose-built architectures such as unikernels.
In the OpenAI case, sandboxing could have prevented the libheif RCE.
Selecting appropriate defense
When you have many applications, services, and infrastructure components to protect, deciding on a strategy and how much effort to invest is as important as the technical implementation itself.
Few people expected a community site such as community.openai.com to become an entry point for hijacking ChatGPT accounts and accessing sensitive internal GitHub repositories. The defense investment for that site and its systems may not have been as high as for other services or infrastructure.
When securing a web application, an assume-breach mindset can help. In addition to searching for vulnerabilities and focusing on components with known CVEs, we should consider the worst-case scenario if an attacker achieves RCE.
Even when no direct attack vector or exploitable path is visible, an application dependency may contain a backdoor, or the threat may come from an insider.
When the investment of resources and effort is proportionate to the risk, threat model, and application context, the protections above can be implemented in layers as risk management based on the Swiss cheese model, creating opportunities for intervention across multiple layers.
My preferred approach is to assume that RCE can happen and then mitigate its impact with sandboxing, supplemented in certain cases by specialized architecture or runtime instrumentation.
Sandboxing

Sandboxes have been used in application security for years. Chrome applies them at the application and system levels. Linux provides seccomp, Linux Security Modules (LSMs), and Landlock. On the client side, Content Security Policy follows the same principle by limiting which resources a page may load.
Web application sandboxing can be difficult because every restriction must preserve expected application behavior. It is still practical. After HacktronAI reported the libheif issue, Discourse added function-level Landlock sandboxing around its ImageMagick calls, although parts of the policy remain relatively permissive.
Discourse's ruby-landlock module shows how dangerous functions can be wrapped with explicit restrictions. Similar protection can cover serialization, file operations, network access, and child processes.
If we want to take a holistic approach beyond function-level controls and sandbox the entire application, we need to account for different forms of RCE. It may involve shell execution or attacker-controlled operations within the application runtime itself. Runtime code or memory corruption may read files, access secrets, or open sockets without invoking /bin/sh or calling execve. A useful sandbox must cover those paths too.
How can we make the sandbox as restrictive as possible against a wide range of RCE impacts without disrupting expected use cases and normal activity? We need to profile the application first.
Profiling with an AI agent
I experimented with an older Discourse Docker image that still contained the vulnerable libheif version. I used GPT-5.6 Sol (TAC with Daybreak Blue) and Codex to assist with testing.
The first step was profiling expected behavior. I used the following prompt:
Deploy a pre July 2026 Discourse Docker version where the vulnerable libheif was still present and Discourse had not yet introduced Landlock sandboxing for ImageMagick.
Run it locally and exercise the application broadly using both privileged and non privileged users. Cover normal features, especially uploads, image processing, attachments, previews, exports, backups, plugins, and background jobs.
Trace runtime behavior in detail, including syscalls, process execution, file reads and writes, filesystem paths, network connections, DNS activity, sockets, and child processes.
The goal is to build an accurate allowlist of legitimate behavior that can later be translated into a strict Landlock policy, supplemented where appropriate by seccomp or other controls, to minimize the blast radius of RCE in the container.
After several rounds of dynamic analysis, the agent collected approximately 700 MB of syscall, file-operation, and network-capture data from Rails, ImageMagick, Nginx, Sidekiq, and other processes inside the container.
The emulated use cases were broad enough to capture executions of /usr/local/bin/convert and /usr/local/bin/magick, along with access to libheif.so.1. This produced an evidence-based map of normal container behavior.
Creating policy with an AI agent
The profiling data can be translated into a strict Landlock policy. File and directory access can be limited, as can the child processes that a particular process may execute. The policy may be applied container-wide from PID 1 or scoped more narrowly to processes such as convert and magick.
After building a protected container image, the agent can replay normal application use cases as positive tests. This verifies that uploads, previews, background jobs, and other expected features still work under the new restrictions.
In my experiment, the agent needed several iterations to produce a minimal ruleset that did not break normal behavior. A policy that blocks the application is secure only in the least useful sense.
Adversarial emulation with an AI agent
I then reproduced the image-upload path against the older and vulnerable libheif version. No practical public PoC was available at the time, so I adjusted the test system and libheif to make the memory corruption easier to trigger without spending excessive tokens.
The agent successfully triggered the exploit, but the sandbox restricted the impact. ImageMagick could not make arbitrary execve calls, read unrelated secrets or files, or create socket connections outside the policy.
The exploit path still existed, but its blast radius was substantially smaller.
This approach proved useful in the libheif case and could also help contain arbitrary binary exploits. But what if the vulnerability exists in the Ruby on Rails web application itself?
As an additional test, I added a vulnerable function to Discourse that allowed dynamic code evaluation and shell injection.
Restricting execve helps substantially against arbitrary shell commands. For dynamic code execution, shell commands, file operations, and network access may still be restricted. However, attacker-controlled code runs in the same runtime context as the application and may access the database, environment variables, and any data available to Rails. We will discuss this challenge in a later section.
Sandboxing challenge
Sandboxing used to be complicated and prone to error. AI can now help significantly with profiling and policy construction, but it does not remove residual risk.
The protections can be improved through continuous iteration to achieve a strong level of security.
As in the Swiss cheese model, the objective is not zero risk. It is to make exploitation harder and reduce the impact of each successful step.
Protection must also be supported by Detection and Response. The behavior allowed by a sandbox should inform monitoring rules and incident-response scenarios.
This experiment was easier because I controlled both the container and host. A serverless function or managed container provides fewer controls and requires a different approach. Landlock also cannot govern every network destination granularly, so combinations with nftables or eBPF remain worth exploring.
From my perspective, this is the kind of work Security Engineers need to research and implement in their organizations, instead of focusing only on chasing CVEs or running noisy security scanners.
Other considerations

For a relatively simple web application, a special-purpose system may provide a smaller attack surface than Linux. A unikernel such as Nanos is one option, although it becomes difficult to use when an application needs many components, binaries, or processes. It's worth exploring, but this approach cannot stop a vulnerability from performing arbitrary operations on data or services that remain available inside the system.
RCE within application runtime code needs a different boundary. An interesting example is Deno permissions, which operate deny-by-default and can restrict each worker's file operations, network destinations, environment variables, and command execution.
new Worker(import.meta.resolve("./trusted.ts"), {
type: "module",
deno: {
permissions: {
read: ["/tmp/"],
write: ["/tmp/"],
net: ["10.0.0.10"],
env: ["MY_SECRET"],
run: false,
ffi: false,
sys: false,
import: false,
}
}
});
new Worker(import.meta.resolve("./else.ts"), {
type: "module",
deno: {
permissions: "none"
}
});Here, trusted.ts receives only the capabilities it needs, while else.ts receives none. The same pattern can keep database access, file access, and secrets inside specific code paths.
Adoption remains limited. In practice, many developers simply enable every permission. Similar protection models are also uncommon in other runtimes and programming languages.
Even with those limitations, this model is promising, especially for code written by agents. I hope more runtimes and development kits adopt similar capabilities.
Cyber kill chain
Several factors shaped the OpenAI hacking scenario demonstrated by HacktronAI. RCE was the entry point in Discourse, but it was only one part of the chain.
The researchers hijacked a ChatGPT account through the site's SSO flow and used its connected Codex session to access private GitHub repositories. A web application compromise had escalated into access to internal code.
When securing an application, we need to model the full attack path. We need to understand how an attacker could move laterally from the initial foothold, which connected systems they could reach, and what they could do after gaining access.
Without the SSO weakness or the Codex-to-GitHub path, the finding might have looked like a minor incident on a community site and received little public attention. The subsequent actions may be controversial, but OpenAI was fortunate that an ethical hacker performed them.
Breaking the attack chain after RCE is as important as preventing RCE itself. This article focuses on reducing the blast radius of the RCE entry point, as subsequent actions vary from case to case.
Application security defense and engineering in the future
Most public application-security harnesses and AI application security companies still focus on finding vulnerabilities. Far fewer use harnesses to design defenses through secure patterns, runtime policy, or custom sandboxes.
The approach is not limited to RCE. Runtime controls can also reduce the impact of SQL injection, broken access control, and logic bugs such as race conditions.
In the past, highly customized protection often met resistance because of maintenance cost and the risk of disrupting a system that already works. AI can absorb part of that load through implementation, testing, profiling, research, and repeated validation.
With the right harness, security experts and agents can build defense-in-depth more efficiently. The same AI capabilities used to write code and find vulnerabilities can help engineers build protections that resist attacks without sacrificing usability or maintainability.

