Skip to content

🛡️ Sentinel: [CRITICAL] Fix LaTeX RCE via Shell Escape - #441

Open
anchapin wants to merge 1 commit into
mainfrom
sentinel/latex-rce-fix-9643023613464355314
Open

anchapin wants to merge 1 commit into
mainfrom
sentinel/latex-rce-fix-9643023613464355314

Conversation

@anchapin

@anchapin anchapin commented Jul 31, 2026 •

Copy link
Copy Markdown
Owner

🚨 Severity: CRITICAL
💡 Vulnerability: PDF compilation commands lacked restricted execution flags (-no-shell-escape), allowing malicious LaTeX input to execute arbitrary system commands via shell escape.
🎯 Impact: An attacker could achieve Remote Code Execution (RCE) on the server.
🔧 Fix: Applied -no-shell-escape to pdflatex and --pdf-engine-opt=-no-shell-escape to pandoc. Added process timeout handling to fail securely.
✅ Verification: Tested PDF compilation functions to ensure flags are correctly applied and fallbacks work on timeout.


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

Summary by Sourcery

Harden LaTeX-based PDF generation against command execution and hangs by restricting shell access and enforcing timeouts on compilation processes.

Bug Fixes:

  • Prevent remote code execution during LaTeX PDF compilation by adding no-shell-escape flags to pdflatex and pandoc invocations.
  • Avoid indefinite hangs in PDF compilation by enforcing a timeout and failing securely when the LaTeX or pandoc process exceeds the limit.

Documentation:

  • Extend Sentinel security notes with details of the LaTeX shell-escape RCE vulnerability and its mitigation.

Applied `-no-shell-escape` to `pdflatex` and `--pdf-engine-opt=-no-shell-escape` to `pandoc` in `cli/pdf/converter.py` and `cli/generators/cover_letter_generator.py` to prevent Remote Code Execution (RCE) vulnerabilities from malicious LaTeX control characters. Also added explicit timeout handling for compilation subprocesses to fail securely on timeout.

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

Sorry @anchapin, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds hardened LaTeX/PDF compilation by disabling shell escape in pdflatex/pandoc and introducing timeouts for the external processes, plus documenting the security issue in Sentinel notes.

Flow diagram for hardened LaTeX PDF compilation with no shell escape and timeouts

flowchart TD
    start([Start _compile_pdf])
    try_pdflatex["Call subprocess.Popen pdflatex -interaction=nonstopmode -no-shell-escape"]
    pdflatex_comm["process.communicate(timeout=30)"]
    pdflatex_timeout{TimeoutExpired?}
    pdflatex_kill["process.kill() and process.communicate()"]
    pdflatex_fail["Return False"]
    pdflatex_success{pdflatex success or output_path exists?}
    set_pdf_true["pdf_created = True"]
    fallback_needed{Need pandoc fallback?}

    try_pandoc["Call subprocess.Popen pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape"]
    pandoc_comm["process.communicate(timeout=30)"]
    pandoc_timeout{TimeoutExpired?}
    pandoc_kill["process.kill() and process.communicate()"]
    pandoc_fail["Return False"]
    pandoc_success{pandoc success or output_path exists?}
    set_pdf_true_fallback["pdf_created = True"]
    end_node([End _compile_pdf])

    start --> try_pdflatex --> pdflatex_comm --> pdflatex_timeout
    pdflatex_timeout -- Yes --> pdflatex_kill --> pdflatex_fail
    pdflatex_timeout -- No --> pdflatex_success
    pdflatex_success -- Yes --> set_pdf_true --> end_node
    pdflatex_success -- No --> fallback_needed

    fallback_needed -- Yes --> try_pandoc --> pandoc_comm --> pandoc_timeout
    pandoc_timeout -- Yes --> pandoc_kill --> pandoc_fail
    pandoc_timeout -- No --> pandoc_success
    pandoc_success -- Yes --> set_pdf_true_fallback --> end_node
    pandoc_success -- No --> end_node

    fallback_needed -- No --> end_node
Loading

File-Level Changes

Change Details Files
Harden cover letter PDF compilation against LaTeX-based RCE and hanging processes.
  • Add -no-shell-escape flag to pdflatex invocation to disable shell escapes.
  • Switch subprocess.communicate to use a bounded timeout and kill the process on timeout, returning failure.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc fallback invocation to propagate shell-escape restrictions to the LaTeX engine.
  • Apply the same shell-escape restriction and timeout handling patterns to both pdflatex and pandoc flows.
cli/generators/cover_letter_generator.py
Apply the same LaTeX PDF hardening (no shell escape + timeouts) to the generic PDF converter utilities.
  • Add -no-shell-escape flag to pdflatex in the converter path.
  • Add communicate timeouts and process.kill() on TimeoutExpired, treating timeouts as failed compilations.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocation used by the converter, with the same timeout handling.
cli/pdf/converter.py
Document the newly discovered LaTeX shell-escape RCE in the security Sentinel record.
  • Add a dated Sentinel entry describing the root cause (missing restricted execution flags), key learning, and prevention pattern for LaTeX compilation commands.
.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

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