Skip to content

🛡️ Sentinel: [CRITICAL] Fix pdflatex RCE vulnerability via missing no-shell-escape flag#284

Open
anchapin wants to merge 1 commit intomainfrom
sentinel/fix-pdflatex-rce-7283270687554969405
Open

🛡️ Sentinel: [CRITICAL] Fix pdflatex RCE vulnerability via missing no-shell-escape flag#284
anchapin wants to merge 1 commit intomainfrom
sentinel/fix-pdflatex-rce-7283270687554969405

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented May 3, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: Secondary PDF compilation processes (cli/pdf/converter.py and CoverLetterGenerator) failed to include the -no-shell-escape flag for pdflatex (and --pdf-engine-opt=-no-shell-escape for pandoc) and lacked execution timeouts, leading to potential Remote Code Execution (RCE) via LaTeX injections and Denial of Service (DoS).
🎯 Impact: An attacker could execute arbitrary commands on the host machine by injecting malicious LaTeX code into the PDF generation pipeline if the inputs weren't properly sanitized. Additionally, crafted inputs could cause infinite compilation loops, exhausting server resources.
🔧 Fix: Added -no-shell-escape arguments to pdflatex and --pdf-engine-opt=-no-shell-escape to pandoc. Added explicit 30-second timeouts and proper process cleanup using subprocess.TimeoutExpired handling.
✅ Verification: Ran Bandit which resulted in no issues found (except a known false positive). Executed full test suite (python -m pytest tests/) which passed, including the security tests in test_pdf_security.py. Verified the changes via read_file inspection.


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

Summary by Sourcery

Harden PDF generation against LaTeX-based RCE and resource exhaustion and document the incident in Sentinel.

Bug Fixes:

  • Prevent Remote Code Execution in secondary LaTeX/PDF compilation paths by ensuring pdflatex and pandoc are invoked with no-shell-escape options.

Enhancements:

  • Add execution timeouts and explicit process cleanup to pdflatex and pandoc subprocesses to mitigate potential Denial of Service from hanging compilations.

Documentation:

  • Record the LaTeX injection and missing no-shell-escape vulnerability, its impact, and recommended prevention measures in the Sentinel security log.

…-shell-escape flag

Adds missing `-no-shell-escape` flags and 30-second timeouts to secondary PDF compilation processes (`cli/pdf/converter.py` and `cli/generators/cover_letter_generator.py`) to prevent Remote Code Execution (RCE) and Denial of Service (DoS) vulnerabilities from untrusted LaTeX inputs.

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

Reviewer's Guide

Adds hardened LaTeX/PDF compilation by enforcing no-shell-escape flags and timeouts for pdflatex/pandoc in secondary PDF generators, and documents the vulnerability/fix in the Sentinel security log.

Sequence diagram for hardened CoverLetterGenerator PDF compilation

sequenceDiagram
    actor User
    participant CoverLetterGenerator
    participant pdflatex_process
    participant pandoc_process
    participant FileSystem

    User->>CoverLetterGenerator: request_pdf_generation()
    CoverLetterGenerator->>FileSystem: write_tex_file()
    CoverLetterGenerator->>pdflatex_process: Popen pdflatex -interaction=nonstopmode -no-shell-escape
    alt pdflatex completes within 30s
        CoverLetterGenerator->>pdflatex_process: communicate timeout=30
        pdflatex_process-->>CoverLetterGenerator: stdout, stderr, returncode
        alt pdflatex success or output_path exists
            CoverLetterGenerator->>CoverLetterGenerator: pdf_created = True
            CoverLetterGenerator-->>User: return True
        else pdflatex failure
            CoverLetterGenerator->>pandoc_process: Popen pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape
            alt pandoc completes within 30s
                CoverLetterGenerator->>pandoc_process: communicate timeout=30
                pandoc_process-->>CoverLetterGenerator: stdout, stderr, returncode
                alt pandoc success or output_path exists
                    CoverLetterGenerator->>CoverLetterGenerator: pdf_created = True
                    CoverLetterGenerator-->>User: return True
                else pandoc failure
                    CoverLetterGenerator-->>User: return False
                end
            else pandoc timeout
                CoverLetterGenerator->>pandoc_process: kill()
                CoverLetterGenerator->>pandoc_process: communicate()
                CoverLetterGenerator-->>User: return False
            end
        end
    else pdflatex timeout
        CoverLetterGenerator->>pdflatex_process: kill()
        CoverLetterGenerator->>pdflatex_process: communicate()
        CoverLetterGenerator-->>User: return False
    end
Loading

Flow diagram for secure LaTeX compilation subprocess pattern

flowchart TD
    A[start_subprocess_with_latex_command] --> B[set_command_flags_include_no_shell_escape]
    B --> C[Popen_with_stdout_stderr_pipes_and_working_directory]
    C --> D[communicate_with_timeout_30s]
    D -->|completed_before_timeout| E[check_returncode_or_output_file_exists]
    D -->|TimeoutExpired| F[call_kill_on_process]
    F --> G[communicate_to_drain_pipes]
    G --> H[return_False]
    E -->|success| I[return_True]
    E -->|failure| H[return_False]
Loading

File-Level Changes

Change Details Files
Harden CoverLetterGenerator LaTeX/PDF compilation against RCE and DoS.
  • Add -no-shell-escape flag to pdflatex invocation to prevent shell escape in LaTeX compilations.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocation using xelatex.
  • Wrap process.communicate calls with a 30-second timeout and handle subprocess.TimeoutExpired by killing the process, consuming remaining output, and returning False.
  • Leave existing success condition that treats either a zero exit code or the existence of the output PDF as success.
cli/generators/cover_letter_generator.py
Harden generic PDF converter LaTeX/PDF compilation against RCE and DoS.
  • Add -no-shell-escape flag to pdflatex invocation used by the converter.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocation used by the converter.
  • Wrap process.communicate calls for both tools with a 30-second timeout and on timeout kill the process, collect remaining output, and return False early.
  • Preserve existing logic that checks both process return code and PDF existence to determine success.
cli/pdf/converter.py
Document the newly discovered LaTeX injection vulnerability and mitigation in Sentinel security notes.
  • Add a new dated section describing the missing no-shell-escape flags and lack of timeouts as a critical RCE/DoS vulnerability.
  • Capture the lesson around duplicated PDF compilation logic missing prior security fixes.
  • Recommend consolidating LaTeX compilation into a single secure utility with standardized flags and timeout handling.
.jules/sentinel.md

Possibly linked issues

  • #Security: Address bandit high severity findings in CI: The PR secures pdflatex/pandoc subprocess calls, removing the high‑severity Bandit findings that were failing CI.

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 new timeout/Popen handling is duplicated in multiple places; consider extracting a shared helper (e.g., run_pdflatex/run_pandoc or a generic run_with_timeout) to centralize the flags, timeout, and cleanup logic.
  • Right now stdout/stderr from the LaTeX and pandoc processes are captured and then discarded; consider logging them or surfacing minimal error information to aid debugging when compilation or timeouts occur.
  • The 30-second timeout is hardcoded in several calls; consider defining a single configuration constant for PDF compilation timeouts so it’s easier to tune and keep consistent across the codebase.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new timeout/`Popen` handling is duplicated in multiple places; consider extracting a shared helper (e.g., `run_pdflatex`/`run_pandoc` or a generic `run_with_timeout`) to centralize the flags, timeout, and cleanup logic.
- Right now `stdout`/`stderr` from the LaTeX and pandoc processes are captured and then discarded; consider logging them or surfacing minimal error information to aid debugging when compilation or timeouts occur.
- The 30-second timeout is hardcoded in several calls; consider defining a single configuration constant for PDF compilation timeouts so it’s easier to tune and keep consistent across the codebase.

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