π‘οΈ Sentinel: [CRITICAL] Fix PDF compilation RCE and DoS risk#343
π‘οΈ Sentinel: [CRITICAL] Fix PDF compilation RCE and DoS risk#343anchapin wants to merge 1 commit into
Conversation
Added `-no-shell-escape` flags to `pdflatex` and `pandoc` commands in `cli/pdf/converter.py` and `cli/generators/cover_letter_generator.py` to prevent arbitrary command execution via malicious LaTeX input. Added 30-second timeouts to `process.communicate()` to prevent infinite compilation loops (DoS), implementing process cleanup (`process.kill()`) and returning False upon timeout. Updated `.jules/sentinel.md` with these learnings. 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 GuideLocks down LaTeX-based PDF compilation to prevent RCE and DoS by adding no-shell-escape flags for pdflatex/pandoc and enforcing timeouts with cleanup on all PDF compilation subprocesses, plus documenting the incident in the Sentinel security log. Sequence diagram for secured LaTeX PDF compilation with timeout and no shell escapesequenceDiagram
participant Caller
participant Converter as PdfConverter
participant Subprocess as subprocess
participant Process as Popen_process
Caller->>Converter: _compile_pdflatex(tex_path, output_path, working_dir)
Converter->>Subprocess: Popen(["pdflatex","-interaction=nonstopmode","-no-shell-escape",tex_path.name])
Subprocess-->>Converter: Process
Converter->>Process: communicate(timeout=30)
alt [TimeoutExpired]
Converter->>Process: kill()
Converter->>Process: communicate()
Converter-->>Caller: return False
else [No timeout]
alt [process.returncode == 0 or output_path.exists()]
Converter-->>Caller: return True
else [Compilation failed]
Converter-->>Caller: return False
end
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 new
Popen+communicate(timeout=30)+TimeoutExpiredhandling is duplicated in multiple places; consider extracting this into a small helper (e.g.,run_compiler(cmd, cwd=None)) to keep the timeout/kill/cleanup logic consistent and easier to maintain. - The
30second timeout is currently an inline magic number in several call sites; defining a shared constant (or configuration option) for the PDF compilation timeout would make the behavior clearer and easier to tune across environments. - On non-timeout failures you currently ignore
stdout/stderrand just returnFalse; consider logging or bubbling up a concise error message so failures inpdflatex/pandocare easier to diagnose in production without relaxing the security posture.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `Popen` + `communicate(timeout=30)` + `TimeoutExpired` handling is duplicated in multiple places; consider extracting this into a small helper (e.g., `run_compiler(cmd, cwd=None)`) to keep the timeout/kill/cleanup logic consistent and easier to maintain.
- The `30` second timeout is currently an inline magic number in several call sites; defining a shared constant (or configuration option) for the PDF compilation timeout would make the behavior clearer and easier to tune across environments.
- On non-timeout failures you currently ignore `stdout`/`stderr` and just return `False`; consider logging or bubbling up a concise error message so failures in `pdflatex`/`pandoc` are easier to diagnose in production without relaxing the security posture.Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
π¨ Severity: CRITICAL
π‘ Vulnerability: PDF compilation via
subprocess.Popenincli/pdf/converter.pyandcli/generators/cover_letter_generator.pyomitted the-no-shell-escapeflag forpdflatexand--pdf-engine-opt=-no-shell-escapefor thepandocfallback, allowing arbitrary command execution if malicious LaTeX input was parsed. Furthermore,process.communicate()was called without timeouts, allowing infinite compilation loops (DoS) if bad input caused the compiler to hang.π― Impact: Remote Code Execution (RCE) via
\write18orshell-escapemechanisms inside LaTeX documents, as well as Denial of Service (DoS) due to hanging compiler threads.π§ Fix: Added
-no-shell-escapeto bothpdflatexandpandocexecution paths, and added a 30-second timeout withprocess.kill()cleanup to allprocess.communicate()calls for PDF compilation.β Verification: Ran pytest tests successfully. Confirmed flags via manual source code review.
PR created automatically by Jules for task 2482042316911710426 started by @anchapin
Summary by Sourcery
Harden PDF compilation against remote code execution and denial-of-service conditions in LaTeX-based workflows.
Bug Fixes:
Documentation: