Skip to content

πŸ›‘οΈ Sentinel: [High] Fix LaTeX RCE and DoS vulnerabilities#346

Open
anchapin wants to merge 1 commit into
mainfrom
sentinel-pdflatex-no-shell-escape-8755560032578265345
Open

πŸ›‘οΈ Sentinel: [High] Fix LaTeX RCE and DoS vulnerabilities#346
anchapin wants to merge 1 commit into
mainfrom
sentinel-pdflatex-no-shell-escape-8755560032578265345

Conversation

@anchapin

@anchapin anchapin commented Jun 7, 2026

Copy link
Copy Markdown
Owner

🚨 Severity: HIGH
πŸ’‘ Vulnerability: Potential Remote Code Execution (RCE) via pdflatex shell 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-escape flags to pdflatex and pandoc commands and introduced timeout=30 with proper TimeoutExpired exception handling and process cleanup.
βœ… Verification: Ran pytest tests/test_pdf_security.py to verify the timeout handling and -no-shell-escape injection 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:

  • Disable LaTeX shell command execution by adding no-shell-escape options to pdflatex and pandoc invocations used for PDF generation.
  • Prevent potential DoS from hanging LaTeX compilation by enforcing a 30-second timeout with proper process termination and error handling in PDF generation routines.

Documentation:

  • Document the LaTeX compilation RCE and DoS vulnerability, its root cause, and the implemented mitigations in the Sentinel security notes.

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>
@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 Jun 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 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-escape

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Harden CoverLetterGenerator LaTeX PDF compilation against RCE and hanging processes.
  • Add -no-shell-escape to pdflatex invocation arguments.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc-based PDF generation fallback.
  • Wrap subprocess.communicate with a 30-second timeout and handle TimeoutExpired by killing the process, draining pipes, and returning failure.
  • Keep existing success condition based on process returncode or output file existence.
cli/generators/cover_letter_generator.py
Apply the same LaTeX compilation hardening to the generic PDF converter.
  • Add -no-shell-escape to pdflatex invocation arguments in the converter.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocation.
  • Use subprocess.communicate with a 30-second timeout and on timeout kill the process, drain output, and return False.
  • Preserve existing return conditions on successful compilation or output file presence.
cli/pdf/converter.py
Document the LaTeX RCE and DoS vulnerability and its mitigations in Sentinel security notes.
  • Add a new dated section describing the RCE risk from pdflatex and pandoc shell execution.
  • Explain the DoS risk from hanging LaTeX compilation processes.
  • Document prevention measures including -no-shell-escape flags, communicate timeouts, and process 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 left some high level feedback:

  • 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.
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.

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.

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