Skip to content

Commit

Permalink
Add sandboxed jinja2 loader for yaml rendering (#10676)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
  • Loading branch information
BenWilson2 authored and harupy committed Dec 14, 2023
1 parent d3311f4 commit 110b737
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mlflow/utils/file_utils.py
Expand Up @@ -329,7 +329,8 @@ def render_and_merge_yaml(root, template_name, context_name):
:param context_name: Name of the context file
:return: Data in yaml file as dictionary
"""
import jinja2
from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.sandbox import SandboxedEnvironment

template_path = os.path.join(root, template_name)
context_path = os.path.join(root, context_name)
Expand All @@ -338,9 +339,9 @@ def render_and_merge_yaml(root, template_name, context_name):
if not pathlib.Path(path).is_file():
raise MissingConfigException(f"Yaml file '{path}' does not exist.")

j2_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(root, encoding=ENCODING),
undefined=jinja2.StrictUndefined,
j2_env = SandboxedEnvironment(
loader=FileSystemLoader(root, encoding=ENCODING),
undefined=StrictUndefined,
line_comment_prefix="#",
)

Expand Down

0 comments on commit 110b737

Please sign in to comment.