π‘οΈ Sentinel: [High] Fix LaTeX RCE and DoS vulnerabilities#346
π‘οΈ Sentinel: [High] Fix LaTeX RCE and DoS vulnerabilities#346anchapin wants to merge 1 commit into
Conversation
Added the `-no-shell-escape` flag to both `pdflatex` and `pandoc` fallback commands in `cli/pdf/converter.py` and `cli/generators/cover_letter_generator.py` to prevent potential Remote Code Execution vulnerabilities when compiling untrusted LaTeX documents. Also added explicit 30-second timeouts to `subprocess.communicate` to mitigate Denial of Service (DoS) risks from hanging compilations. 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 GuideAdds shell-escape hardening and timeout-based DoS protection to LaTeX PDF generation via pdflatex and pandoc, and documents the vulnerability in Sentinel notes. Sequence diagram for hardened LaTeX PDF compilation with timeout and no-shell-escapesequenceDiagram
participant Generator as CoverLetterGenerator
participant Converter as PDFConverter
participant Subprocess as subprocess
participant Pdflatex as pdflatex/pandoc
Generator->>Converter: _compile_pdf/_compile_pdflatex/_compile_pandoc
Converter->>Subprocess: Popen(["pdflatex","-interaction=nonstopmode","-no-shell-escape",tex_path.name])
Note over Converter,Subprocess: or Popen(["pandoc",tex_path,"-o",output_path,"--pdf-engine=xelatex","--pdf-engine-opt=-no-shell-escape"])
Subprocess->>Pdflatex: start process
alt within 30s
Converter->>Subprocess: process.communicate(timeout=30)
Subprocess-->>Converter: stdout, stderr
Converter->>Converter: check process.returncode or output_path.exists()
Converter-->>Generator: return True/False
else timeout
Converter->>Subprocess: process.communicate(timeout=30)
Subprocess-->>Converter: TimeoutExpired
Converter->>Subprocess: process.kill()
Converter->>Subprocess: process.communicate()
Converter-->>Generator: 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 timeout and
Popenhandling logic forpdflatex/pandocis duplicated in multiple places; consider extracting a shared helper (with a singleDEFAULT_LATEX_TIMEOUTconstant) to reduce repetition and keep behavior consistent across callers. - On timeout or non-zero return codes, the stdout/stderr from
pdflatex/pandocare discarded; consider logging or surfacing these messages so it's easier to diagnose why PDF generation failed or hit the timeout.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The timeout and `Popen` handling logic for `pdflatex`/`pandoc` is duplicated in multiple places; consider extracting a shared helper (with a single `DEFAULT_LATEX_TIMEOUT` constant) to reduce repetition and keep behavior consistent across callers.
- On timeout or non-zero return codes, the stdout/stderr from `pdflatex`/`pandoc` are discarded; consider logging or surfacing these messages so it's easier to diagnose why PDF generation failed or hit the timeout.Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
π¨ Severity: HIGH
π‘ Vulnerability: Potential Remote Code Execution (RCE) via
pdflatexshell execution capabilities and Denial of Service (DoS) via hanging processes.π― Impact: Untrusted LaTeX templates could execute arbitrary system commands or cause the application to hang indefinitely.
π§ Fix: Added
-no-shell-escapeflags topdflatexandpandoccommands and introducedtimeout=30with properTimeoutExpiredexception handling and process cleanup.β Verification: Ran
pytest tests/test_pdf_security.pyto verify the timeout handling and-no-shell-escapeinjection on the mocked subprocesses.PR created automatically by Jules for task 8755560032578265345 started by @anchapin
Summary by Sourcery
Harden LaTeX-based PDF generation against RCE and hanging processes in the cover letter generator and PDF converter.
Bug Fixes:
Documentation: