Skip to content

🛡️ Sentinel: [CRITICAL] Fix pdflatex RCE and DoS vulnerabilities#341

Open
anchapin wants to merge 1 commit into
mainfrom
sentinel/fix-pdflatex-rce-and-dos-mitigation-8184241153704705132
Open

🛡️ Sentinel: [CRITICAL] Fix pdflatex RCE and DoS vulnerabilities#341
anchapin wants to merge 1 commit into
mainfrom
sentinel/fix-pdflatex-rce-and-dos-mitigation-8184241153704705132

Conversation

@anchapin

@anchapin anchapin commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Severity: CRITICAL
Vulnerability: PDF compilation via pdflatex and pandoc in cli/pdf/converter.py and cli/generators/cover_letter_generator.py omitted the -no-shell-escape flag and did not enforce an execution timeout.
Impact: This allowed malicious untrusted input to execute arbitrary shell commands via LaTeX (\write18), leading to Remote Code Execution (RCE), as well as infinite compilation loops leading to Denial of Service (DoS).
Fix: Explicitly added -no-shell-escape (or --pdf-engine-opt=-no-shell-escape for pandoc) to all execution commands. Additionally added timeout=30 to process.communicate() to prevent hangs, and correctly caught subprocess.TimeoutExpired to kill the zombie processes and safely skip completion logic.
Verification: Verified via manual source checking via sed and ran full test suite (python -m pytest tests/) to ensure no regressions. All 681 tests passed successfully.


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

Summary by Sourcery

Harden PDF generation against RCE and DoS via external LaTeX tools.

Bug Fixes:

  • Disable LaTeX shell escape in pdflatex and pandoc PDF compilation to prevent command execution vulnerabilities.
  • Add timeouts and proper timeout handling for pdflatex and pandoc subprocesses to avoid hanging and DoS during PDF generation.

Documentation:

  • Document the pdflatex/pandoc RCE and DoS vulnerability, its root cause, and required mitigations in the Sentinel security log.

Enforce -no-shell-escape flag and explicit 30-second timeouts on all pdflatex and pandoc subprocess executions in cli/pdf/converter.py and cli/generators/cover_letter_generator.py to prevent LaTeX-based Remote Code Execution and infinite loop Denial of Service vulnerabilities via untrusted input. Also correctly handles TimeoutExpired to prevent zombie processes and prevents false-positive successful returns on timeouts.

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 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

Hardened LaTeX/PDF generation by disabling shell escape and adding timeouts around pdflatex/pandoc subprocesses, plus documenting the security issue in Sentinel notes.

Sequence diagram for hardened pdflatex compilation with timeout and no-shell-escape

sequenceDiagram
    participant Caller as PdfConverter
    participant Converter as _compile_pdflatex
    participant Subproc as subprocess.Popen
    participant Proc as process

    Caller->>Converter: _compile_pdflatex(tex_path, working_dir, output_path)
    Converter->>Subproc: Popen(["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name])
    Note right of Subproc: returns process
    Subproc-->>Converter: process

    alt process completes within 30s
        Converter->>Proc: communicate(timeout=30)
        Proc-->>Converter: stdout, stderr
        Converter->>Caller: return True or False based on
        Note right of Converter: True if returncode==0 or output_path.exists()
    else subprocess.TimeoutExpired
        Converter->>Proc: kill()
        Converter->>Proc: communicate()
        Proc-->>Converter: stdout, stderr
        Converter->>Caller: return False
    end
Loading

File-Level Changes

Change Details Files
Harden pdflatex invocation in cover letter generator against RCE and hangs.
  • Added -no-shell-escape flag to pdflatex command to prevent shell execution via LaTeX.
  • Wrapped process.communicate() with a 30-second timeout and handled subprocess.TimeoutExpired by killing the process and avoiding success flags.
  • Applied the same timeout-and-kill pattern to the pandoc fallback path, including not marking PDF creation as successful on timeout.
cli/generators/cover_letter_generator.py
Secure core PDF converter’s pdflatex and pandoc pipelines with shell-escape restrictions and timeouts.
  • Added -no-shell-escape to pdflatex invocation to disable LaTeX shell escapes.
  • Configured pandoc to pass --pdf-engine-opt=-no-shell-escape through to xelatex.
  • Introduced a 30-second timeout when waiting on subprocesses and treated timeouts as failures after killing the child process.
cli/pdf/converter.py
Document the pdflatex RCE/DoS vulnerability and mitigation in Sentinel security notes.
  • Added a new Sentinel entry describing the missing -no-shell-escape and timeout as a critical issue.
  • Documented learnings about dangerous defaults in external build tools and the need for explicit timeouts.
  • Recorded prevention guidelines for always using -no-shell-escape and timeouts in PDF compilation pipelines.
.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 subprocess timeout/kill logic is duplicated across pdflatex and pandoc calls; consider extracting a small helper (e.g., run_with_timeout(cmd, cwd, timeout=30)) to centralize behavior and make future changes less error-prone.
  • The hardcoded timeout=30 value is repeated in multiple places; promoting this to a shared constant (or configuration option) would make it easier to adjust globally if needed and keep the timeout policy consistent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The subprocess timeout/kill logic is duplicated across pdflatex and pandoc calls; consider extracting a small helper (e.g., `run_with_timeout(cmd, cwd, timeout=30)`) to centralize behavior and make future changes less error-prone.
- The hardcoded `timeout=30` value is repeated in multiple places; promoting this to a shared constant (or configuration option) would make it easier to adjust globally if needed and keep the timeout policy consistent.

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