Skip to content

🛡️ Sentinel: [CRITICAL] Fix LaTeX RCE and DoS vulnerabilities#328

Open
anchapin wants to merge 2 commits into
mainfrom
sentinel-latex-rce-dos-fix-16815568420048628348
Open

🛡️ Sentinel: [CRITICAL] Fix LaTeX RCE and DoS vulnerabilities#328
anchapin wants to merge 2 commits into
mainfrom
sentinel-latex-rce-dos-fix-16815568420048628348

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented May 30, 2026

🛡️ Sentinel: [CRITICAL] Fix LaTeX RCE and DoS vulnerabilities

🚨 Severity: CRITICAL
💡 Vulnerability: Remote Code Execution (RCE) via LaTeX shell escape and Denial of Service (DoS) via infinite compilation loops in pdflatex and pandoc subprocesses.
🎯 Impact: An attacker or AI hallucination could inject malicious LaTeX commands (like \write18) to execute arbitrary shell commands on the server, or provide malformed LaTeX to hang the compilation process indefinitely, starving resources.
🔧 Fix: Added -no-shell-escape flag to both pdflatex and pandoc (via --pdf-engine-opt) to strictly disable shell command execution. Implemented 30-second timeouts on all subprocess.communicate() calls, properly killing and cleaning up processes if they hang.
Verification: Ran the unit test suite natively and verified via git diff that the correct arguments and exception handling blocks are correctly in place. Also documented learning in .jules/sentinel.md.


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

Summary by Sourcery

Harden LaTeX-based PDF generation against remote code execution and denial-of-service conditions.

Bug Fixes:

  • Disable LaTeX shell escape for pdflatex and pandoc-based PDF generation to prevent arbitrary command execution.
  • Add timeouts and cleanup for LaTeX compilation subprocesses to avoid hangs and potential DoS when compilation loops indefinitely.

Documentation:

  • Document the LaTeX shell escape and DoS vulnerabilities, their impact, and mitigation patterns in .jules/sentinel.md.

Severity: CRITICAL
Vulnerability: Remote Code Execution (RCE) via LaTeX shell escape and Denial of Service (DoS) via infinite compilation loops in pdflatex and pandoc subprocesses.
Impact: An attacker or AI hallucination could inject malicious LaTeX commands (like \write18) to execute arbitrary shell commands on the server, or provide malformed LaTeX to hang the compilation process indefinitely, starving resources.
Fix: Added `-no-shell-escape` flag to both pdflatex and pandoc (via --pdf-engine-opt) to strictly disable shell command execution. Implemented 30-second timeouts on all subprocess.communicate() calls, properly killing and cleaning up processes if they hang.
Verification: Ran the unit test suite natively and verified via `git diff` that the correct arguments and exception handling blocks are correctly in place.

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
Copy link
Copy Markdown

sourcery-ai Bot commented May 30, 2026

Reviewer's Guide

Harden LaTeX PDF generation by disabling shell escape for pdflatex/pandoc and adding time-bounded subprocess handling to prevent RCE and DoS during PDF compilation in both the cover letter generator and generic PDF converter, plus documenting the issue in Sentinel notes.

Sequence diagram for hardened LaTeX PDF compilation with timeout and no shell escape

sequenceDiagram
    participant CoverLetterGenerator
    participant pdflatex
    participant pandoc

    CoverLetterGenerator->>pdflatex: Popen(["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name])
    alt pdflatex completes within 30s
        pdflatex-->>CoverLetterGenerator: communicate(timeout=30)
        alt pdflatex success or output_path.exists()
            CoverLetterGenerator->>CoverLetterGenerator: pdf_created = True
        else pdflatex failure
            CoverLetterGenerator->>CoverLetterGenerator: pdf_created = False
        end
    else pdflatex hangs
        CoverLetterGenerator->>pdflatex: kill()
        pdflatex-->>CoverLetterGenerator: communicate()
        CoverLetterGenerator->>CoverLetterGenerator: pdf_created = False

        CoverLetterGenerator->>pandoc: Popen(["pandoc", tex_path, "-o", output_path, "--pdf-engine=xelatex", "--pdf-engine-opt=-no-shell-escape"])
        alt pandoc completes within 30s
            pandoc-->>CoverLetterGenerator: communicate(timeout=30)
            alt pandoc success or output_path.exists()
                CoverLetterGenerator->>CoverLetterGenerator: pdf_created = True
            else pandoc failure
                CoverLetterGenerator->>CoverLetterGenerator: pdf_created = False
            end
        else pandoc hangs
            CoverLetterGenerator->>pandoc: kill()
            pandoc-->>CoverLetterGenerator: communicate()
            CoverLetterGenerator->>CoverLetterGenerator: pdf_created = False
        end
    end
Loading

File-Level Changes

Change Details Files
Disable LaTeX shell escape in all pdflatex and pandoc PDF compilation paths to prevent RCE.
  • Add -no-shell-escape flag to pdflatex invocation used by the cover letter generator when compiling LaTeX to PDF.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocation used as a fallback PDF engine in the cover letter generator.
  • Add -no-shell-escape flag to pdflatex invocation used by the generic PDF converter.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocation used by the generic PDF converter.
cli/generators/cover_letter_generator.py
cli/pdf/converter.py
Introduce robust timeouts and cleanup for LaTeX compilation subprocesses to mitigate DoS via infinite loops or hangs.
  • Wrap pdflatex and pandoc subprocess.communicate() calls in 30-second timeouts in the cover letter generator, killing hung processes and marking PDF generation as failed when a timeout occurs.
  • Wrap pdflatex and pandoc subprocess.communicate() calls in 30-second timeouts in the generic PDF converter, killing hung processes and returning False on timeout to signal failure.
  • Ensure subprocesses are properly killed and communicate() is re-run after timeout to avoid zombie or partially cleaned-up processes.
cli/generators/cover_letter_generator.py
cli/pdf/converter.py
Document the LaTeX shell escape and DoS vulnerabilities and mitigations in the Sentinel security notes.
  • Add a new Sentinel entry describing the lack of -no-shell-escape and timeouts as critical vulnerabilities in LaTeX compilation.
  • Capture learnings about dangerous defaults in document compilation tools and the need for explicit shell-escape disabling and strict subprocess timeouts.
  • Document prevention guidelines for future work, including always adding -no-shell-escape and wrapping communicate() with timeout/cleanup logic.
.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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The timeout handling is inconsistent between cover_letter_generator._compile_pdf and pdf.converter (one sets pdf_created = False and continues, the other returns early); consider unifying the behavior so that a timed-out compilation is always treated the same way and does not fall through to the success checks.
  • In _compile_pdf, after a TimeoutExpired you still run the if process.returncode == 0 or output_path.exists() block; if a timeout should be a hard failure, it would be safer to return immediately or guard that success check so a partially written or stale PDF doesn’t cause the compile to be reported as successful.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The timeout handling is inconsistent between `cover_letter_generator._compile_pdf` and `pdf.converter` (one sets `pdf_created = False` and continues, the other returns early); consider unifying the behavior so that a timed-out compilation is always treated the same way and does not fall through to the success checks.
- In `_compile_pdf`, after a `TimeoutExpired` you still run the `if process.returncode == 0 or output_path.exists()` block; if a timeout should be a hard failure, it would be safer to return immediately or guard that success check so a partially written or stale PDF doesn’t cause the compile to be reported as successful.

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.

Severity: CRITICAL
Vulnerability: Remote Code Execution (RCE) via LaTeX shell escape and Denial of Service (DoS) via infinite compilation loops in pdflatex and pandoc subprocesses.
Impact: An attacker or AI hallucination could inject malicious LaTeX commands (like \write18) to execute arbitrary shell commands on the server, or provide malformed LaTeX to hang the compilation process indefinitely, starving resources.
Fix: Added `-no-shell-escape` flag to both pdflatex and pandoc (via --pdf-engine-opt) to strictly disable shell command execution. Implemented 30-second timeouts on all subprocess.communicate() calls, properly killing and cleaning up processes if they hang.
Verification: Ran the unit test suite natively and verified via `git diff` that the correct arguments and exception handling blocks are correctly in place.

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