upatch.dev

CVE-2026-79310

webpy web.py 0.76 is vulnerable to server-side template injection (SSTI).

Refuses web.py template precompilation writes to __init__.py to mitigate CVE-2026-79310.

High 8.5Vetted

EPSS 0.7%: the estimated chance this CVE is exploited in the next 30 days, as of 24 Nov 2026.

At a glance

CVE-2026-79310 is a high (CVSS 8.5) vulnerability in web.py, published 23 September 2026. A vetted upatch, cve-2026-79310-webpy-block, blocks it on running Linux machines with shirudo until web.py is upgraded.

Severity
High 8.5 CVSS 3.1
Chance of exploitation
0.7% in the next 30 days (EPSS, 24 Nov 2026)
Known exploited
No, not on CISA’s KEV list
Weakness
CWE-94
Affected software
web.py (webpy)
Upatch status
Vetted, merged into the registry
How to apply
Build, sign and roll out with shirudo

Overview

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.

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.

Sources

More references from NVD (2)

Mitigation

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.

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.

The policy

122 lines of BPF C, attached at lsm/inode_create and lsm/file_open.

// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>

#define EPERM	1
#define FMODE_WRITE	0x2

char _license[] SEC("license") = "Dual BSD/GPL";

enum {
	REFUSED_CREATE,
	REFUSED_OPEN,
	NR_COUNTERS,
};

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
	__uint(max_entries, NR_COUNTERS);
	__type(key, __u32);
	__type(value, __u64);
} refused SEC(".maps");

static __always_inline void count(__u32 key)
{
	__u64 *value = bpf_map_lookup_elem(&refused, &key);

	if (value)
		__sync_fetch_and_add(value, 1);
}

static __always_inline bool is_init_py(const struct dentry *dentry)
{
	const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
	char buf[12] = {};

	if (!dentry || BPF_CORE_READ(dentry, d_name.len) != 11)
		return false;
	if (!name || bpf_probe_read_kernel(buf, 11, name))
		return false;
	return buf[0] == '_' && buf[1] == '_' && buf[2] == 'i' &&
	       buf[3] == 'n' && buf[4] == 'i' && buf[5] == 't' &&
	       buf[6] == '_' && buf[7] == '_' && buf[8] == '.' &&
	       buf[9] == 'p' && buf[10] == 'y';
}

static __always_inline bool is_templates_dir(const struct dentry *dir)
{
	const unsigned char *name = BPF_CORE_READ(dir, d_name.name);
	char buf[10] = {};

	if (!dir || BPF_CORE_READ(dir, d_name.len) != 9)
		return false;
	if (!name || bpf_probe_read_kernel(buf, 9, name))
		return false;
	return buf[0] == 't' && buf[1] == 'e' && buf[2] == 'm' &&
	       buf[3] == 'p' && buf[4] == 'l' && buf[5] == 'a' &&
	       buf[6] == 't' && buf[7] == 'e' && buf[8] == 's';
}

static __always_inline bool in_templates_tree(const struct dentry *dentry)
{
	const struct dentry *dir = BPF_CORE_READ(dentry, d_parent);

	for (int i = 0; i < 4; i++) {
		if (!dir)
			return false;
		if (is_templates_dir(dir))
			return true;
		dir = BPF_CORE_READ(dir, d_parent);
	}
	return false;
}

static __always_inline bool current_is_python(void)
{
	char comm[16] = {};

	if (bpf_get_current_comm(&comm, sizeof(comm)))
		return false;
	return comm[0] == 'p' && comm[1] == 'y' && comm[2] == 't' &&
	       comm[3] == 'h' && comm[4] == 'o' && comm[5] == 'n';
}

static __always_inline int earlier_verdict(int ret)
{
	return ret >= -4095 && ret < 0 ? ret : -EPERM;
}

SEC("lsm/inode_create")
int BPF_PROG(cve_2026_79310_create, const struct mnt_idmap *idmap,
	     struct inode *dir, struct dentry *dentry, umode_t mode, int ret)
{
	if (ret)
		return earlier_verdict(ret);
	if (!is_init_py(dentry))
		return 0;
	if (!current_is_python() || !in_templates_tree(dentry))
		return 0;
	count(REFUSED_CREATE);
	return -EPERM;
}

SEC("lsm/file_open")
int BPF_PROG(cve_2026_79310_open, struct file *file, int ret)
{
	const struct dentry *dentry = file->f_path.dentry;

	if (ret)
		return earlier_verdict(ret);
	if (!(file->f_mode & FMODE_WRITE))
		return 0;
	if (!is_init_py(dentry))
		return 0;
	if (!current_is_python() || !in_templates_tree(dentry))
		return 0;
	count(REFUSED_OPEN);
	return -EPERM;
}

Process

How this upatch was written, checked and reviewed, from the registry’s history.

  1. 23 Sept 2026CVECVE published
  2. 25 Nov 2026Pull requestPull request #51 openedAdd CVE-2026-79310: Refuses web.py template precompilation writes to __init__.pyromanlab
  3. 25 Nov 2026MergeMerged #51romanlab
  4. 25 Nov 2026ReviewReviewedqodo-code-review[bot] (automated)

No human review is recorded on GitHub for this upatch yet.

Evidence

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
StateRuntime compile_templates writes templates/__init__.pyNormal template render
Before loadingyes (HTTP 200)yes (HTTP 200)
Upatch loadedno (HTTP 403 / EPERM)yes (HTTP 200)
After unloadingyes (HTTP 200)yes (HTTP 200)
tools-test.log Output of tools/test --setup showing compile_templates reached before and after the upatch was loaded and blocked while loaded.
tools/test --setup, 2026-11-25T12:39:40Z
Target: shirudo test VM, Linux 7.4-shirudo-ci-20261123, x86_64, swtpm
cve-2026-79310
  setup   done         WEBPY_URL=http://127.0.0.1:36103 WEBPY_TEMPLATES=/opt/upatch-payload/cve-2026-79310/app/templates
  before  reached      compile_templates wrote __init__.py in the templates directory (HTTP 200); removed it
  loaded  blocked      compile_templates failed with EPERM (HTTP 403) and wrote no __init__.py
  after   reached      compile_templates wrote __init__.py in the templates directory (HTTP 200); removed it
  PASS: reached before, blocked while loaded, reached again after

Use it

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
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
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>