Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix pdflatex and pandoc Remote Code Execution (RCE) via shell escape#319

Open
anchapin wants to merge 1 commit into
mainfrom
sentinel/fix-pdflatex-rce-17456038898672213850
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix pdflatex and pandoc Remote Code Execution (RCE) via shell escape#319
anchapin wants to merge 1 commit into
mainfrom
sentinel/fix-pdflatex-rce-17456038898672213850

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented May 24, 2026

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: PDF compilation commands (pdflatex and pandoc fallbacks) executed untrusted .tex templates without sandboxing (-no-shell-escape) and without timeouts, exposing the system to Remote Code Execution (RCE) via \write18 and Denial of Service (DoS) via infinite compilation loops. Even fallback processes like pandoc act as vectors for LaTeX-based exploits if they trigger a LaTeX engine under the hood.
🎯 Impact: Malicious actors could use hallucinatory AI inputs or malicious prompt injections to generate LaTeX payloads that execute arbitrary shell commands on the host machine or intentionally hang the compilation process indefinitely.
πŸ”§ Fix:

  • Added -no-shell-escape flag to all pdflatex subprocess calls in cli/pdf/converter.py and cli/generators/cover_letter_generator.py.
  • Added --pdf-engine-opt=-no-shell-escape flag to all pandoc fallback calls.
  • Enforced a 30-second subprocess timeout.
  • Implemented explicit process cleanup (process.kill() and a subsequent .communicate()) in except subprocess.TimeoutExpired blocks to prevent zombie processes and double-free issues.
    βœ… Verification: Verified by successfully running the full test suite (python -m pytest) which showed 681 tests passing. Reviewed modified files to ensure correct flag placement and robust cleanup logic.

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

Summary by Sourcery

Harden LaTeX-based PDF generation to prevent remote code execution and hangs in compilation subprocesses.

Bug Fixes:

  • Prevent remote code execution and denial-of-service vulnerabilities in pdflatex and pandoc-based PDF compilation by sandboxing and bounding subprocess execution.

Enhancements:

  • Add sandboxing flags to pdflatex and pandoc PDF compilation paths and enforce timeouts with explicit process cleanup on timeout to avoid zombie processes.

Documentation:

  • Extend Sentinel security log with details of the LaTeX and pandoc RCE/DoS vulnerability and its mitigations.

…and DoS vulnerabilities

Add `-no-shell-escape` flags and 30-second timeouts with explicit process cleanup to all PDF compilation subprocess calls to prevent arbitrary code execution via `\write18` and infinite loop DoS attacks.

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

Reviewer's Guide

Hardened LaTeX/PDF compilation by disabling shell escapes, adding timeouts, and ensuring robust subprocess cleanup for both pdflatex and pandoc paths, plus documenting the vulnerability in the Sentinel security log.

Sequence diagram for hardened LaTeX PDF compilation with timeout and sandboxing

sequenceDiagram
    participant Caller as CoverLetterGenerator
    participant Converter as _compile_pdf/_compile_pdflatex
    participant Subprocess as subprocess

    Caller->>Converter: _compile_pdf / _compile_pdflatex(tex_path, output_path)
    Converter->>Subprocess: Popen([pdflatex|-pandoc, -no-shell-escape], cwd)
    activate Subprocess
    alt within_30_seconds
        Converter->>Subprocess: process.communicate(timeout=30)
        Subprocess-->>Converter: stdout, stderr
        deactivate Subprocess
        Converter->>Converter: check process.returncode or output_path.exists()
        Converter-->>Caller: True/False
    else timeout_Expired
        Converter->>Subprocess: process.kill()
        Subprocess-->>Converter: communicate()
        Converter-->>Caller: False
    end
Loading

File-Level Changes

Change Details Files
Harden pdflatex compilation in the cover letter generator.
  • Add -no-shell-escape to pdflatex invocation to prevent shell command execution from LaTeX.
  • Wrap process.communicate with a 30-second timeout to avoid hanging compilations.
  • On subprocess.TimeoutExpired, kill the pdflatex process, drain output via communicate, and return False to signal failure.
  • Retain existing success condition using return code or output file existence.
cli/generators/cover_letter_generator.py
Secure pandoc fallback PDF generation in the cover letter generator.
  • Add --pdf-engine-opt=-no-shell-escape when invoking pandoc with xelatex to disable shell escapes in the underlying LaTeX engine.
  • Wrap pandoc process.communicate with a 30-second timeout.
  • On timeout, kill the pandoc process, drain output, and return False to signal fallback failure while avoiding zombie processes.
cli/generators/cover_letter_generator.py
Apply the same hardened pdflatex behavior in the shared PDF converter module.
  • Add -no-shell-escape to all pdflatex invocations in the converter.
  • Introduce a 30-second timeout around process.communicate.
  • On timeout, kill the process, then call communicate again and return False to indicate compilation failure.
cli/pdf/converter.py
Secure pandoc-based compilation in the PDF converter module.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocations that use xelatex.
  • Enforce a 30-second timeout on pandoc communicate calls.
  • On timeout, kill the process, then communicate and return False, mirroring the pdflatex error-handling pattern.
cli/pdf/converter.py
Document the LaTeX and Pandoc RCE/DoS vulnerability and mitigation in Sentinel security notes.
  • Add a dated entry describing the prior lack of sandboxing and timeouts for LaTeX compilation paths.
  • Record learnings about pandoc acting as a LaTeX exploit vector and the risks of incomplete timeout handling.
  • Document preventive practices: always use -no-shell-escape/--pdf-engine-opt and explicit cleanup on timeouts.
.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 30-second timeout is hard-coded in multiple places; consider centralizing this value (and possibly making it configurable) to avoid duplication and ease future tuning.
  • The subprocess invocation and timeout/cleanup pattern is repeated for both pdflatex and pandoc; factoring this into a small helper function would reduce duplication and potential for divergence.
  • On timeout you currently discard stderr/stdout after killing the process; consider logging or surfacing at least a summarized error to help diagnose recurring hangs or misconfigurations in LaTeX/pandoc.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The 30-second timeout is hard-coded in multiple places; consider centralizing this value (and possibly making it configurable) to avoid duplication and ease future tuning.
- The subprocess invocation and timeout/cleanup pattern is repeated for both pdflatex and pandoc; factoring this into a small helper function would reduce duplication and potential for divergence.
- On timeout you currently discard stderr/stdout after killing the process; consider logging or surfacing at least a summarized error to help diagnose recurring hangs or misconfigurations in LaTeX/pandoc.

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