Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential fix for code scanning alert no. 2: Jinja2 templating with autoescape=False #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions latest_changes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from github import Github
from github.PullRequest import PullRequest
from jinja2 import Template
from jinja2 import Environment, FileSystemLoader, select_autoescape
from pydantic import BaseModel, SecretStr
from pydantic_settings import BaseSettings

Expand Down Expand Up @@ -92,7 +92,11 @@ def generate_content(
f"The latest changes file at: {settings.input_latest_changes_file} doesn't seem to contain the header RegEx: {settings.input_latest_changes_header}"
)
template_content = settings.input_template_file.read_text("utf-8")
template = Template(template_content)
env = Environment(
loader=FileSystemLoader(searchpath=str(settings.input_template_file.parent)),
autoescape=select_autoescape(['html', 'xml'])
)
template = env.from_string(template_content)
message = template.render(pr=pr)
if message in content:
raise RuntimeError(
Expand Down