# CVE-2026-79310: webpy web.py 0.76 is vulnerable to server-side template injection (SSTI).

The Markdown version of <https://upatch.dev/cve/CVE-2026-79310>. Last updated 25 Nov 2026.

## At a glance

CVE-2026-79310 is rated High 8.5 (CVSS 3.1, CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:H). It affects web.py (webpy) and was published on 23 Sept 2026. It is not in CISA's Known Exploited Vulnerabilities catalog. Its EPSS score is 0.7%: the estimated chance it is exploited in the next 30 days, as of 24 Nov 2026. The upatch `cve-2026-79310-webpy-block` mitigates it, and is vetted (merged into the registry).

A upatch is a signed BPF program that shirudo loads into a running Linux kernel to block the code path this CVE's exploit takes. It holds the line until the fix ships; it does not replace patching.

## The vulnerability

CVE-2026-79310, published on 23 September 2026, is a server-side template injection and code injection vulnerability (CWE-94) in `web.py` 0.76. In `web/template.py`, `compile_templates(root)` walks a directory of template files and writes generated Python functions into `__init__.py` inside each directory before calling `Template(..., path)` to run `SafeVisitor().walk()` over the generated AST. Even when `SafeVisitor` raises `SecurityError` on forbidden template constructs, the generated Python code has already been written to `__init__.py` on disk. When the application loads precompiled templates through `GAE_Render`, it imports that `__init__.py` module and executes the template functions outside the restricted template sandbox, leading to arbitrary Python and OS command execution.

### Official description

webpy web.py 0.76 is vulnerable to server-side template injection (SSTI). The template engine can be tricked into executing attacker-controlled template code that built-in security checks are designed to reject. When an application precompiles templates from a directory the attacker can write to and later renders them through the precompiled template loader, the sandbox is bypassed and the attacker's code runs, resulting in arbitrary Python code execution and OS command execution on the server.

## What the upatch does

Two BPF LSM programs return `-EPERM` to processes whose command name starts with `python` when they attempt to write `__init__.py` inside a `templates` directory (or up to three subdirectory levels below `templates`):

| Hook               | Refused                                                                             |
| ------------------ | ----------------------------------------------------------------------------------- |
| `lsm/inode_create` | Creating a file named `__init__.py` under a `templates` directory                   |
| `lsm/file_open`    | Opening a file named `__init__.py` with `FMODE_WRITE` under a `templates` directory |

Both hooks check the dentry name length (`11`) and exact match against `__init__.py` first, and `file_open` checks `FMODE_WRITE` before inspecting the dentry name, so read opens and all other file names return immediately.

The `refused` per-CPU array counts refusals: key 0 for `inode_create` and key 1 for `file_open`.

The policy: [`cve-2026-79310-webpy-block.bpf.c`](https://github.com/copper-helm/upatch-registry/tree/main/upatches/cve-2026-79310), 122 lines of BPF C attached at `lsm/inode_create` and `lsm/file_open`, licensed GPL-2.0 OR BSD-2-Clause.

## Side effects

- Calling `web.template.compile_templates()` at runtime from a Python process on a `templates` directory fails with `PermissionError` (`EPERM`) when opening `templates/__init__.py` for writing, matching the advisory's mitigation of disallowing runtime batch precompilation on writable template directories.
- Standard `web.template.render()` template loading and read-only importing of precompiled `__init__.py` modules created during a build step continue to work normally.
- Non-Python processes (such as system utilities or `root` shells) and Python processes writing outside a `templates` directory can create and modify `__init__.py` files without restriction.

## Preemption model and cost

The programs share no state other than the `refused` per-CPU counter array, which is updated with `__sync_fetch_and_add`, making them safe under `PREEMPT_LAZY`, preemptible RCU, and `PREEMPT_RT`. On every `inode_create`, a non-matching file returns after comparing `d_name.len != 11`. On every `file_open`, read-only opens return after testing `file->f_mode & FMODE_WRITE`, and write opens of any file whose name is not 11 bytes long return immediately.

## Affected versions

The vulnerability is in the `web.py` application library (`v0.76`, commit `99e5eed8e3a210b4951ca1ed5cb5575479a25c99`, and earlier `0.x` versions with `compile_templates`); no upstream fix was published as of the advisory date.

On the kernel side, the upatch uses the `lsm/inode_create` and `lsm/file_open` hooks with the four-argument `inode_create` prototype (`const struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode`) used in Linux 6.3 and later, including Linux 7.4.

## How it was tested

On a vulnerable web.py 0.76 server, the loaded upatch refused runtime template precompilation writes to templates/\_\_init\_\_.py (HTTP 403 / EPERM) while normal template rendering kept working.

- **Tested:** 25 Nov 2026
- **Target:** web.py 0.76 on Python 3.12 with runtime web.template.compile_templates endpoint, loopback only
- **Kernel:** 7.4-shirudo-ci-20261123
- **Architecture:** x86_64
- **Distribution:** Ubuntu 26.04

### Results

| State           | Runtime compile_templates writes templates/\_\_init\_\_.py | Normal template render |
| --------------- | ---------------------------------------------------------- | ---------------------- |
| Before loading  | yes (HTTP 200)                                             | yes (HTTP 200)         |
| Upatch loaded   | no (HTTP 403 / EPERM)                                      | yes (HTTP 200)         |
| After unloading | yes (HTTP 200)                                             | yes (HTTP 200)         |

## How to apply

Build the upatch from source, sign it with your own shirudo key, and publish it to your own OCI registry. Machines that follow your upatch tree load it within about a minute.

Build and sign:

```sh
git clone https://github.com/copper-helm/upatch-registry
cd upatch-registry
tools/build <shirudo-checkout> <keys-dir> 1.0.0 upatches/cve-2026-79310
```

Publish and roll out:

```sh
shirudo bpm push build/packages/cve-2026-79310-1.0.0.bee oci://<registry>/<namespace>/cve-2026-79310 --keys-dir <keys-dir>
shirudo bpm tree append build/packages/cve-2026-79310-1.0.0.bee oci://<registry>/<namespace>/<tree> --tree-id <tree-id> --keys-dir <keys-dir>
```

## Review

- Contributors: romanlab.
- Reviewers: none recorded yet.

## Sources and links

- [CVE-2026-79310 record (CVE API)](https://cveawg.mitre.org/api/cve/CVE-2026-79310)
- [CVE-2026-79310 advisory](https://github.com/lichoin/TraceLoom/blob/main/CVEs/CVE-2026-79310.md)
- [web.py repository and `web/template.py`](https://github.com/webpy/webpy/blob/master/web/template.py)
- [web.py v0.76 release](https://github.com/webpy/webpy/releases/tag/v0.76)

### Links

- [CVE-2026-79310 on upatch.dev](https://upatch.dev/cve/CVE-2026-79310) (this page, as HTML)
- [NVD](https://nvd.nist.gov/vuln/detail/CVE-2026-79310)
- [CVE.org](https://www.cve.org/CVERecord?id=CVE-2026-79310)
- [CWE-94](https://cwe.mitre.org/data/definitions/94.html)
- Upatch source: [upatches/cve-2026-79310](https://github.com/copper-helm/upatch-registry/tree/main/upatches/cve-2026-79310)

### More references from NVD (2)

- [github.com](https://github.com/lichoin/TraceLoom/blob/main/CVEs/CVE-2026-79310.md)
- [github.com](https://github.com/webpy/webpy)
