Summary
web.py 0.76 contains a server-side template injection vulnerability that can bypass built-in template security checks when attacker-controlled templates are precompiled and later rendered.
If an attacker can write to the template source directory, the resulting code execution may allow arbitrary Python operations and OS command execution on the server.
Affected context
The vulnerability occurs in web.py applications that:
- Use the web.py template engine
- Precompile templates from a directory that an attacker can modify
- Later render those templates through the precompiled template loader
- Rely on template security checks that do not remain effective across the precompilation and loading boundary
The risk depends on whether untrusted users or processes can write template source files or influence the precompiled template workflow.
Exploit preconditions
- Attack surface: Server-side template compilation and rendering
- Required access: Ability to write or otherwise control files in the template source directory
- Trigger point: Application precompilation followed by rendering through the precompiled template loader
- Why exploitation is possible: Attacker-controlled template code can be embedded during precompilation and later executed outside the intended sandbox restrictions
Why this happens
The underlying issue is a server-side template injection flaw caused by treating attacker-influenced template source as trusted code during precompilation.
Security checks intended to reject dangerous template constructs are bypassed because the precompiled template path does not preserve the same trust and validation guarantees as the normal template-processing path. This maps to CWE-94: Improper Control of Generation of Code, where input can influence the creation or execution of program code.
Potential impact
- Arbitrary Python code execution on the application server
- OS command execution with the privileges of the web application
- Access to application secrets, files, and environment variables
- Modification or destruction of application data
- Potential lateral movement into connected services or infrastructure
General mitigation guidance
Mitigation generally focuses on preventing untrusted content from entering executable template workflows and maintaining consistent validation across all rendering paths.
Common defensive patterns include:
- Treating templates as trusted application code rather than user-controlled data
- Preventing untrusted users and processes from writing to template directories
- Using non-executable rendering mechanisms for user-provided content
- Applying strict allowlisted template syntax and validation before compilation
- Separating template storage from writable upload and temporary-file locations
- Running the application with least privilege and restricting access to sensitive resources
- Limiting available operating-system capabilities for the rendering process
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules identifying dynamic template compilation or rendering of user-influenced paths
- Code review checks for writable template directories and precompiled-template loaders
- Taint analysis tracing file writes or request data into template compilation APIs
- Runtime monitoring for unexpected template creation, compilation, or execution
- File integrity policies that restrict changes to application template directories
- CI security checks that test whether sandbox restrictions remain effective across compilation and loading paths
Automated code review and application security testing tools may help identify unsafe template flows, but findings should be validated against the application's actual file-permission and rendering design.

