Skip to content

🛡️ Sentinel: [CRITICAL] Fix LaTeX Injection RCE and DoS in PDF Compilation - #423

Open
anchapin wants to merge 2 commits into
mainfrom
sentinel/fix-pdflatex-rce-and-dos-mitigation-9727106323628115774
Open

🛡️ Sentinel: [CRITICAL] Fix LaTeX Injection RCE and DoS in PDF Compilation#423
anchapin wants to merge 2 commits into
mainfrom
sentinel/fix-pdflatex-rce-and-dos-mitigation-9727106323628115774

Conversation

@anchapin

@anchapin anchapin commented Jul 21, 2026

Copy link
Copy Markdown
Owner

🚨 Severity: CRITICAL
💡 Vulnerability: LaTeX injection RCE and DoS without timeouts in CoverLetterGenerator and PDFConverter
🎯 Impact: Arbitrary code execution or Denial of Service
🔧 Fix: Add -no-shell-escape flags and 30s timeouts
✅ Verification: Tests pass.


PR created automatically by Jules for task 9727106323628115774 started by @anchapin

Summary by Sourcery

Harden LaTeX-based PDF generation against remote code execution and hangs by restricting compiler capabilities and enforcing time-bounded execution.

Bug Fixes:

  • Disable LaTeX shell escape in pdflatex and pandoc PDF compilation paths in the cover letter generator and generic PDF converter to prevent command execution via injected LaTeX.
  • Add 30-second timeouts and cleanup on LaTeX and pandoc compilation to avoid indefinite hangs and associated Denial of Service conditions.

Documentation:

  • Update Sentinel security notes with a new entry documenting the LaTeX injection RCE and DoS vulnerability, its root cause, and the applied mitigations.

Tests:

  • Extend PDF security tests to verify that pdflatex and pandoc are invoked with no-shell-escape options and that compilation correctly times out and terminates on long-running processes.

…ation

Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds defensive flags and timeouts around LaTeX/PDF compilation in PDFConverter and CoverLetterGenerator to mitigate LaTeX injection RCE and DoS, and introduces tests plus Sentinel documentation for these behaviors.

Sequence diagram for secured LaTeX PDF compilation with flags and timeout

sequenceDiagram
    participant Caller
    participant CoverLetterGenerator
    participant PDFConverter
    participant subprocess

    Caller->>CoverLetterGenerator: _compile_pdf(output_path, tex_content)
    CoverLetterGenerator->>subprocess: Popen(["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name])
    alt pdflatex completes within 30s
        CoverLetterGenerator->>subprocess: process.communicate(timeout=30)
        subprocess-->>CoverLetterGenerator: stdout, stderr
        CoverLetterGenerator-->>Caller: pdf_created or fallback to pandoc
    else pdflatex times out
        CoverLetterGenerator->>subprocess: process.kill()
        CoverLetterGenerator->>subprocess: process.communicate()
        CoverLetterGenerator-->>Caller: False
    end

    Caller->>PDFConverter: _compile_pdflatex(output_path, tex_path, working_dir)
    PDFConverter->>subprocess: Popen(["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name])
    alt pdflatex completes within 30s
        PDFConverter->>subprocess: process.communicate(timeout=30)
        subprocess-->>PDFConverter: stdout, stderr
        PDFConverter-->>Caller: True
    else pdflatex times out
        PDFConverter->>subprocess: process.kill()
        PDFConverter->>subprocess: process.communicate()
        PDFConverter-->>Caller: False
    end

    Caller->>PDFConverter: _compile_pandoc(output_path, tex_path, working_dir)
    PDFConverter->>subprocess: Popen(["pandoc", tex_path, "-o", output_path, "--pdf-engine=xelatex", "--pdf-engine-opt=-no-shell-escape"]) 
    alt pandoc completes within 30s
        PDFConverter->>subprocess: process.communicate(timeout=30)
        subprocess-->>PDFConverter: stdout, stderr
        PDFConverter-->>Caller: True
    else pandoc times out
        PDFConverter->>subprocess: process.kill()
        PDFConverter->>subprocess: process.communicate()
        PDFConverter-->>Caller: False
    end
Loading

File-Level Changes

Change Details Files
Harden pdflatex and pandoc invocation in CoverLetterGenerator against RCE and DoS.
  • Add -no-shell-escape to pdflatex CLI arguments when compiling cover letter PDFs.
  • Wrap pdflatex communicate() with a 30-second timeout, killing the process and returning False on TimeoutExpired.
  • Extend the pandoc fallback invocation to pass --pdf-engine-opt=-no-shell-escape to disable shell escapes in the LaTeX engine.
  • Add a 30-second timeout (with kill and False return) around pandoc communicate() to prevent hanging compilers.
cli/generators/cover_letter_generator.py
Harden pdflatex and pandoc invocation in generic PDFConverter against RCE and DoS.
  • Add -no-shell-escape to pdflatex CLI arguments for TeX compilation.
  • Add a 30-second timeout around pdflatex communicate(), killing the process and returning False on TimeoutExpired to indicate failure.
  • Extend pandoc invocation to include --pdf-engine-opt=-no-shell-escape when using xelatex as the PDF engine.
  • Add a 30-second timeout around pandoc communicate(), killing the process and returning False on TimeoutExpired to signal failure.
cli/pdf/converter.py
Add regression tests to validate flags and timeout behavior for LaTeX and PDF compilation flows.
  • Introduce tests that mock subprocess.Popen for PDFConverter pdflatex and pandoc paths, asserting 30-second timeouts trigger kill() and False return when outputs do not exist.
  • Add tests that verify -no-shell-escape and --pdf-engine-opt=-no-shell-escape are present in pdflatex and pandoc commands for PDFConverter.
  • Introduce tests for CoverLetterGenerator._compile_pdf that set up minimal config/env, assert 30-second timeout kills pdflatex and returns False, and confirm -no-shell-escape/-interaction flags are present in normal invocations.
tests/test_pdf_security.py
Document the new LaTeX injection mitigation in Sentinel security log.
  • Append a new Sentinel entry describing the prior vulnerability (missing -no-shell-escape and timeouts), the learning, and the prevention guidelines for LaTeX compilation.
  • Clarify that pdflatex and pandoc must always be invoked with shell escapes disabled and with enforced timeouts and cleanup.
.jules/sentinel.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

…ation

Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant