CVE-2021-44657
StackStorm < 3.6.0: Unsafe Jinja interpreter, command execution vulnerability (no sandbox)
- CVSS 8.8
- CWE-94 Improper Control of Generation of Code ('Code Injection')
- Input Validation and Sanitization
- Remote
In StackStorm versions prior to 3.6.0, the jinja interpreter was not run in sandbox mode and thus allows execution of unsafe system commands. Jinja does not enable sandboxed mode by default due to backwards compatibility. Stackstorm now sets sandboxed mode for jinja by default.
- CVSS base score
- 8.8
- Published
- 2021-12-15
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- StackStorm
- Fixed by upgrading
- Yes
Solution
Update StackStorm to version 3.6.0 or higher.
Vulnerable code sample
from jinja2 import Environment, FileSystemLoader
# Create a Jinja2 environment without sandbox mode
env = Environment(
loader=FileSystemLoader('templates')
)
# Example of rendering a template that could execute unsafe commands
template = env.get_template('example_template.html')
output = template.render(variable='{{ system("echo vulnerable") }}')
print(output)Patched code sample
from jinja2 import Environment, FileSystemLoader, select_autoescape
# Create a Jinja2 environment with sandbox mode enabled
env = Environment(
loader=FileSystemLoader('templates'),
autoescape=select_autoescape(['html', 'xml']),
enable_async=True # Optional: to enable async support if needed
)
# Example of rendering a template safely
template = env.get_template('example_template.html')
output = template.render(variable='safe_value')
print(output)Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Use Jinja sandboxed environment (stackstorm/st2)
st2common/st2common/util/jinja.py · get_jinja_environment,st2common/st2common/util/param.py · _process_defaults,st2common/st2common/util/param.py · _resolve_dependencies,st2common/st2common/util/param.py · _validate,tools/st2-analyze-links.py · Grapher.generate_graph,tools/visualize_action_chain.py · main
Cite this entry
@misc{vaitp:cve202144657,
title = {{StackStorm < 3.6.0: Unsafe Jinja interpreter, command execution vulnerability (no sandbox)}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2021},
note = {VAITP Python Vulnerability Dataset, entry CVE-2021-44657},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-44657/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
