🛡️ Sentinel: [CRITICAL] Fix LaTeX RCE and DoS Vulnerabilities#330
🛡️ Sentinel: [CRITICAL] Fix LaTeX RCE and DoS Vulnerabilities#330anchapin wants to merge 2 commits into
Conversation
This prevents arbitrary command execution (RCE) via LaTeX's \write18 feature and prevents Denial of Service (DoS) attacks from infinite compilation loops. Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's GuideHardened LaTeX-based PDF generation by disabling shell escapes and adding robust timeouts around pdflatex/pandoc subprocesses, plus documenting the security fix in the Sentinel security log. Sequence diagram for secured LaTeX PDF generation with timeoutsequenceDiagram
participant PdfGenerator
participant subprocess
participant process
PdfGenerator->>subprocess: Popen(["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name])
subprocess-->>PdfGenerator: process
alt [within 30 seconds]
PdfGenerator->>process: communicate(timeout=30)
process-->>PdfGenerator: stdout, stderr
PdfGenerator->>PdfGenerator: [check process.returncode or output_path.exists]
else [timeout]
PdfGenerator->>process: communicate(timeout=30)
process--xPdfGenerator: TimeoutExpired
PdfGenerator->>process: kill()
PdfGenerator->>process: communicate()
PdfGenerator-->>PdfGenerator: return False
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The subprocess timeout and kill logic is duplicated in four places; consider extracting a small helper function (e.g.,
run_with_timeout(cmd, cwd, timeout=30)) to centralize this behavior and reduce the risk of divergence in future changes. - Right now a timeout simply returns
Falsewith no visibility; it may be helpful to log or surface a specific error message for timeout cases so operators can distinguish them from normal LaTeX failures. - The 30-second timeout is currently a magic number; consider making it a named constant or configurable setting so it can be tuned without editing multiple call sites.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The subprocess timeout and kill logic is duplicated in four places; consider extracting a small helper function (e.g., `run_with_timeout(cmd, cwd, timeout=30)`) to centralize this behavior and reduce the risk of divergence in future changes.
- Right now a timeout simply returns `False` with no visibility; it may be helpful to log or surface a specific error message for timeout cases so operators can distinguish them from normal LaTeX failures.
- The 30-second timeout is currently a magic number; consider making it a named constant or configurable setting so it can be tuned without editing multiple call sites.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This prevents arbitrary command execution (RCE) via LaTeX's \write18 feature and prevents Denial of Service (DoS) attacks from infinite compilation loops. Fixed formatting to pass black CI checks. Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
🚨 Severity: CRITICAL
💡 Vulnerability:
pdflatexandpandocwere executed without-no-shell-escapeand timeouts in multiple modules (cli/pdf/converter.pyandcli/generators/cover_letter_generator.py).🎯 Impact: Allows Local File Inclusion (LFI) and Remote Code Execution (RCE) via LaTeX injections, and infinite loop/DoS attacks via missing timeouts.
🔧 Fix: Added
-no-shell-escapeand--pdf-engine-opt=-no-shell-escapearguments and implemented a 30s timeout with process kill handling.✅ Verification: Ran
python -m pytest tests/test_pdf_security.pyand the full test suite to verify the timeout handling and correct CLI arguments.PR created automatically by Jules for task 8058454716389122478 started by @anchapin
Summary by Sourcery
Harden PDF generation against LaTeX-based RCE and DoS vectors by locking down pdflatex/pandoc execution and enforcing timeouts.
Bug Fixes:
Documentation: