Fix #208: Prevent SSTI in responder_mgr.py Jinja2 template
- Use jinja2.Environment with BaseLoader instead of Template - Enable autoescape=True to escape all template variables - Sanitize relay_targets by converting to strings: [str(ip) for ip in ...] - Prevents template injection even if relay_targets contains malicious content
This commit is contained in:
@@ -267,12 +267,14 @@ class ResponderManager(BaseModule):
|
|||||||
template_path = os.path.join(self._template_dir, "Responder.conf.j2")
|
template_path = os.path.join(self._template_dir, "Responder.conf.j2")
|
||||||
if os.path.isfile(template_path):
|
if os.path.isfile(template_path):
|
||||||
try:
|
try:
|
||||||
from jinja2 import Template
|
from jinja2 import Environment, BaseLoader
|
||||||
with open(template_path, "r") as f:
|
with open(template_path, "r") as f:
|
||||||
tmpl = Template(f.read())
|
template_content = f.read()
|
||||||
|
env = Environment(loader=BaseLoader(), autoescape=True)
|
||||||
|
tmpl = env.from_string(template_content)
|
||||||
rendered = tmpl.render(
|
rendered = tmpl.render(
|
||||||
protocols=self._protocols,
|
protocols=self._protocols,
|
||||||
relay_targets=self._relay_targets,
|
relay_targets=[str(ip) for ip in self._relay_targets],
|
||||||
interface=self._iface,
|
interface=self._iface,
|
||||||
)
|
)
|
||||||
with open(conf_path, "w") as f:
|
with open(conf_path, "w") as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user