π‘οΈ Sentinel: [CRITICAL] Fix Remote Code Execution in PDF Generation#275
π‘οΈ Sentinel: [CRITICAL] Fix Remote Code Execution in PDF Generation#275
Conversation
Adds -no-shell-escape flags and 30-second timeouts to pdflatex and pandoc subprocess invocations in cover letter generation and pdf conversion modules. This prevents arbitrary code execution and infinite compilation loops when generating PDFs from user input. Co-authored-by: anchapin <[email protected]>
|
π 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-to-PDF generation by disabling shell escapes for pdflatex/pandoc and adding 30s timeouts with cleanup to all PDF compilation subprocesses, plus documenting the incident in the Sentinel playbook. Sequence diagram for hardened cover letter PDF compilation with timeout and fallbacksequenceDiagram
participant CoverLetterGenerator
participant PdflatexProcess
participant PandocProcess
CoverLetterGenerator->>PdflatexProcess: Popen pdflatex -interaction=nonstopmode -no-shell-escape
alt pdflatex completes within 30s
PdflatexProcess-->>CoverLetterGenerator: communicate timeout=30
alt returncode == 0 or output_path exists
CoverLetterGenerator->>CoverLetterGenerator: set pdf_created true
else pdflatex nonzero exit
CoverLetterGenerator->>CoverLetterGenerator: raise CalledProcessError
CoverLetterGenerator->>PandocProcess: Popen pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape
alt pandoc completes within 30s
PandocProcess-->>CoverLetterGenerator: communicate timeout=30
alt returncode == 0 or output_path exists
CoverLetterGenerator->>CoverLetterGenerator: set pdf_created true
else pandoc nonzero exit
CoverLetterGenerator->>CoverLetterGenerator: handle failure pdf_created remains false
end
else pandoc TimeoutExpired
CoverLetterGenerator->>PandocProcess: kill
PandocProcess-->>CoverLetterGenerator: communicate drain
CoverLetterGenerator->>CoverLetterGenerator: handle failure pdf_created remains false
end
end
else pdflatex TimeoutExpired
CoverLetterGenerator->>PdflatexProcess: kill
PdflatexProcess-->>CoverLetterGenerator: communicate drain
CoverLetterGenerator->>CoverLetterGenerator: raise CalledProcessError to trigger fallback
CoverLetterGenerator->>PandocProcess: Popen pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape
alt pandoc completes within 30s
PandocProcess-->>CoverLetterGenerator: communicate timeout=30
alt returncode == 0 or output_path exists
CoverLetterGenerator->>CoverLetterGenerator: set pdf_created true
else pandoc nonzero exit
CoverLetterGenerator->>CoverLetterGenerator: handle failure pdf_created remains false
end
else pandoc TimeoutExpired
CoverLetterGenerator->>PandocProcess: kill
PandocProcess-->>CoverLetterGenerator: communicate drain
CoverLetterGenerator->>CoverLetterGenerator: handle failure pdf_created remains false
end
end
Flow diagram for secured LaTeX PDF compilation subprocesses in converterflowchart TD
Start[[Start _compile_pdflatex or _compile_pandoc]]
A[Create subprocess with security flags
pdflatex -interaction=nonstopmode -no-shell-escape
or
pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape]
B{communicate timeout=30
TimeoutExpired?}
C[Kill process]
D[Drain output with communicate]
E[Return False to caller]
F{process returncode == 0
or output_path exists?}
G[Return True to caller]
H[Raise CalledProcessError or handle as failure]
Start --> A --> B
B -- Yes --> C --> D --> E
B -- No --> F
F -- Yes --> G
F -- No --> H --> E
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/kill/communicate pattern is duplicated across multiple call sites; consider extracting a small helper (e.g.,
run_with_timeout(cmd, cwd=None, timeout=30) -> CompletedProcess|None) to centralize the behavior and avoid drift in future changes. - Right now a timeout is treated the same as other
CalledProcessErrorpaths; if distinguishing timeouts from regular compilation failures would be useful, consider surfacing that via a specific exception type, return value, or log message so callers can react differently (e.g., inform users vs. silently falling back).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The subprocess timeout/kill/communicate pattern is duplicated across multiple call sites; consider extracting a small helper (e.g., `run_with_timeout(cmd, cwd=None, timeout=30) -> CompletedProcess|None`) to centralize the behavior and avoid drift in future changes.
- Right now a timeout is treated the same as other `CalledProcessError` paths; if distinguishing timeouts from regular compilation failures would be useful, consider surfacing that via a specific exception type, return value, or log message so callers can react differently (e.g., inform users vs. silently falling back).Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
π¨ Severity: CRITICAL
π‘ Vulnerability: Remote Code Execution (RCE) and Denial of Service (DoS) in PDF Generation.
pdflatexandpandocwere invoked without the-no-shell-escapeflag or a process timeout incli/pdf/converter.pyandcli/generators/cover_letter_generator.py. This allows malicious LaTeX input (e.g.\write18{...}) to execute arbitrary shell commands on the host system.π― Impact: Complete system compromise via arbitrary command execution if an attacker can control the LaTeX input. Potential DoS by causing an infinite compilation loop.
π§ Fix: Added
-no-shell-escapetopdflatexand--pdf-engine-opt=-no-shell-escapetopandocinvocations. Added a 30-secondtimeoutto allprocess.communicate()calls with proper error handling and process termination.β Verification: Verified by reviewing the code changes, ensuring all subprocess interactions correctly handle timeouts and cleanups, and executing the test suite successfully. Evaluated test cases confirming the
pdflatexflag inclusion and timeout logic. Also appended learning to.jules/sentinel.md.PR created automatically by Jules for task 7659911145396587821 started by @anchapin
Summary by Sourcery
Harden PDF generation against remote code execution and hangs by securing LaTeX subprocess invocations.
Bug Fixes:
Documentation: