Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
**Vulnerability:** The `CoverLetterGenerator` used a standard Jinja2 environment (intended for HTML/XML or plain text) to render LaTeX templates. This allowed malicious user input (or AI hallucinations) containing LaTeX control characters (e.g., `\input{...}`) to be injected directly into the LaTeX source, leading to potential Local File Inclusion (LFI) or other exploits.
**Learning:** Jinja2's default `autoescape` is context-aware based on file extensions, but usually only for HTML/XML. It does NOT automatically escape LaTeX special characters. Relying on manual filters (like `| latex_escape`) in templates is error-prone and brittle, as developers might forget to apply them to every variable.
**Prevention:** Always use a dedicated Jinja2 environment for LaTeX generation that enforces auto-escaping via a `finalize` hook (e.g., `tex_env.finalize = latex_escape`). This ensures *all* variable output is sanitized by default, providing defense-in-depth even if the template author forgets explicit filters.

## 2026-07-03 - Fix PDF Compilation Command Injection and Resource Exhaustion Risks
**Vulnerability:** Subprocess calls to `pdflatex` and `pandoc` lacked timeouts, risking resource exhaustion, and lacked shell-escape restrictions, risking command injection (RCE) via malicious LaTeX content.
**Learning:** Subprocess execution of external binaries, particularly TeX engines, must always enforce resource limits and disable shell escapes to prevent arbitrary execution.
**Prevention:** Always use `-no-shell-escape` with `pdflatex` and enforce a `timeout` on `process.communicate()` with proper process cleanup.
31 changes: 27 additions & 4 deletions cli/generators/cover_letter_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,22 @@ def _compile_pdf(self, output_path: Path, tex_content: str) -> bool:

pdf_created = False
try:
# Added -no-shell-escape to prevent RCE
# Use Popen with explicit cleanup to avoid double-free issues
process = subprocess.Popen(
["pdflatex", "-interaction=nonstopmode", tex_path.name],
["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=tex_path.parent,
)
stdout, stderr = process.communicate()
try:
# Added timeout to prevent resource exhaustion (DoS)
stdout, stderr = process.communicate(timeout=30)
except subprocess.TimeoutExpired:
process.kill()
process.communicate()
pdf_created = False

if process.returncode == 0 or output_path.exists():
pdf_created = True
except (subprocess.CalledProcessError, FileNotFoundError):
Expand All @@ -786,12 +794,27 @@ def _compile_pdf(self, output_path: Path, tex_content: str) -> bool:
else:
# Fallback to pandoc
try:
# Added --pdf-engine-opt=-no-shell-escape to prevent RCE
process = subprocess.Popen(
["pandoc", str(tex_path), "-o", str(output_path), "--pdf-engine=xelatex"],
[
"pandoc",
str(tex_path),
"-o",
str(output_path),
"--pdf-engine=xelatex",
"--pdf-engine-opt=-no-shell-escape",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = process.communicate()
try:
# Added timeout to prevent resource exhaustion (DoS)
stdout, stderr = process.communicate(timeout=30)
except subprocess.TimeoutExpired:
process.kill()
process.communicate()
pdf_created = False

if process.returncode == 0 or output_path.exists():
pdf_created = True
except (subprocess.CalledProcessError, FileNotFoundError):
Expand Down
31 changes: 27 additions & 4 deletions cli/pdf/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,21 @@ def _compile_pdflatex(
True if PDF was created successfully
"""
try:
# Added -no-shell-escape to prevent RCE from malicious LaTeX
process = subprocess.Popen(
["pdflatex", "-interaction=nonstopmode", tex_path.name],
["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=working_dir,
)
stdout, stderr = process.communicate()
try:
# Added timeout to prevent resource exhaustion (DoS)
stdout, stderr = process.communicate(timeout=30)
except subprocess.TimeoutExpired:
# Explicitly cleanup process if timed out
process.kill()
process.communicate()
return False

if process.returncode == 0 or output_path.exists():
return True
Expand Down Expand Up @@ -120,13 +128,28 @@ def _compile_pandoc(
True if PDF was created successfully
"""
try:
# Added --pdf-engine-opt=-no-shell-escape to prevent RCE
process = subprocess.Popen(
["pandoc", str(tex_path), "-o", str(output_path), "--pdf-engine=xelatex"],
[
"pandoc",
str(tex_path),
"-o",
str(output_path),
"--pdf-engine=xelatex",
"--pdf-engine-opt=-no-shell-escape",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=working_dir,
)
stdout, stderr = process.communicate()
try:
# Added timeout to prevent resource exhaustion (DoS)
stdout, stderr = process.communicate(timeout=30)
except subprocess.TimeoutExpired:
# Explicitly cleanup process if timed out
process.kill()
process.communicate()
return False

if process.returncode == 0 or output_path.exists():
return True
Expand Down
2 changes: 1 addition & 1 deletion resume_pdf_lib/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def latex_escape(text: Any) -> Markup:

i += 1

return Markup("".join(result))
return Markup("".join(result)) # nosec B704


def proper_title(text: str) -> str:
Expand Down
Loading