Skip to content

🛡️ Sentinel: [CRITICAL] Fix LaTeX injection RCE vulnerability in PDF compilation#274

Open
anchapin wants to merge 2 commits intomainfrom
sentinel-pdf-rce-fix-7895040161886264509
Open

🛡️ Sentinel: [CRITICAL] Fix LaTeX injection RCE vulnerability in PDF compilation#274
anchapin wants to merge 2 commits intomainfrom
sentinel-pdf-rce-fix-7895040161886264509

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented Apr 29, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: The cli/pdf/converter.py and cli/generators/cover_letter_generator.py modules used subprocess.Popen to call pdflatex and pandoc without -no-shell-escape flags or process timeouts, enabling Remote Code Execution (RCE) and Denial of Service (DoS) attacks from untrusted LaTeX inputs.
🎯 Impact: Attackers could execute arbitrary system commands on the host machine or hang the application indefinitely.
🔧 Fix: Appended -no-shell-escape and --pdf-engine-opt=-no-shell-escape to pdflatex and pandoc subprocess arguments respectively, added a 30-second timeout to process.communicate(), and ensured process cleanup.
✅ Verification: Ran unit tests via pytest to confirm successful timeout detection and proper argument forwarding.


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

Summary by Sourcery

Harden PDF compilation against LaTeX-based RCE and DoS by constraining external tools and enforcing execution time limits.

Bug Fixes:

  • Prevent remote code execution by disabling shell escapes when invoking pdflatex and pandoc in PDF generation paths.
  • Mitigate denial-of-service risk by adding timeouts and explicit cleanup for long-running LaTeX compilation subprocesses.

Documentation:

  • Document the newly identified LaTeX injection RCE and DoS vulnerability and its mitigations in the Sentinel security history.

@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 Apr 29, 2026

Reviewer's Guide

Adds defense-in-depth against LaTeX-based RCE and DoS in PDF compilation by enforcing no-shell-escape flags for pdflatex/pandoc, introducing 30s timeouts with cleanup for all LaTeX compilation subprocesses, and documenting the incident in the Sentinel security log.

Sequence diagram for hardened LaTeX PDF compilation subprocess handling

sequenceDiagram
    participant Caller as Caller
    participant Subproc as Subprocess
    participant Pdflatex as pdflatex
    participant Pandoc as pandoc

    Caller->>Subproc: Popen(["pdflatex","-interaction=nonstopmode","-no-shell-escape",tex_path_name])
    activate Subproc
    Subproc->>Pdflatex: execute pdflatex

    alt pdflatex finishes within 30s
        Subproc-->>Caller: communicate(timeout=30)
        Caller->>Caller: check returncode or output_path_exists
        alt success
            Caller->>Caller: pdf_created True
        else failure
            Caller->>Subproc: Popen(["pandoc",tex_path,"-o",output_path,"--pdf-engine=xelatex","--pdf-engine-opt=-no-shell-escape"])
            activate Subproc
            Subproc->>Pandoc: execute pandoc
            alt pandoc finishes within 30s
                Subproc-->>Caller: communicate(timeout=30)
                Caller->>Caller: check returncode or output_path_exists
                alt success
                    Caller->>Caller: pdf_created True
                else failure
                    Caller->>Caller: pdf_created False
                end
            else pandoc timeout
                Subproc-->>Caller: TimeoutExpired
                Caller->>Subproc: kill()
                Caller->>Subproc: communicate()
                Caller->>Caller: pdf_created False
            end
        end
    else pdflatex timeout
        Subproc-->>Caller: TimeoutExpired
        Caller->>Subproc: kill()
        Caller->>Subproc: communicate()
        Caller->>Caller: pdf_created False
        Caller->>Caller: optionally try pandoc fallback
    end
Loading

Flow diagram for LaTeX PDF compilation with no_shell_escape and timeout

flowchart TD
    Start([Start PDF compilation]) --> PDFA[Run pdflatex with flags]
    PDFA["Popen pdflatex with -interaction=nonstopmode and -no-shell-escape"] --> PDFCOMM["communicate(timeout=30)"]

    PDFCOMM -->|finished| PDFRC{pdflatex success or output_path exists}
    PDFCOMM -->|TimeoutExpired| PDFTO[Kill pdflatex process and communicate]

    PDFTO --> PDFFAIL[Mark pdflatex attempt failed]

    PDFRC -->|yes| OK[Return success]
    PDFRC -->|no| PANDOCCHK{Use pandoc fallback available}

    PANDOCCHK -->|no| FAIL[Return failure]
    PANDOCCHK -->|yes| PANDA["Popen pandoc with --pdf-engine=xelatex and --pdf-engine-opt=-no-shell-escape"]

    PANDA --> PANCOMM["communicate(timeout=30)"]

    PANCOMM -->|finished| PANRC{pandoc success or output_path exists}
    PANCOMM -->|TimeoutExpired| PANTO[Kill pandoc process and communicate]

    PANTO --> PANFAIL[Mark pandoc attempt failed]
    PANFAIL --> FAIL

    PANRC -->|yes| OK
    PANRC -->|no| FAIL

    OK --> End([End: PDF compiled safely])
    FAIL --> End
Loading

File-Level Changes

Change Details Files
Harden pdflatex and pandoc invocations in cover letter PDF generation against RCE and hangs.
  • Append -no-shell-escape to pdflatex arguments to disable shell command execution within LaTeX.
  • Append --pdf-engine-opt=-no-shell-escape to pandoc invocations using xelatex as the PDF engine.
  • Wrap process.communicate calls with a 30-second timeout and handle subprocess.TimeoutExpired by killing the process, draining remaining output, and marking compilation as failed.
  • Preserve existing success criteria by still treating compilation as successful if either the process returns zero or the expected PDF file already exists.
cli/generators/cover_letter_generator.py
Apply the same subprocess hardening for general LaTeX-to-PDF conversion utilities.
  • Add -no-shell-escape flag to pdflatex calls to prevent shell escapes during LaTeX compilation.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocations to enforce no-shell-escape in the xelatex engine.
  • Introduce a 30-second timeout around subprocess.communicate; on timeout, kill the process, drain its output, and return False to signal failed compilation.
  • Keep output existence as an additional success condition alongside zero return code.
cli/pdf/converter.py
Document the LaTeX injection RCE class of vulnerabilities and the mitigations taken in the Sentinel security playbook.
  • Add a new dated entry describing the LaTeX compilation RCE and DoS risk from unsafe pdflatex/pandoc defaults and missing timeouts.
  • Record the security learnings about unsafe defaults and the importance of no-shell-escape and timeouts when invoking external compilers.
  • Describe preventive measures, including enforced no-shell-escape flags and mandatory subprocess timeouts for external tools.
.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:

  • Consider extracting the 30-second timeout value into a shared constant so it’s easier to tune and keep consistent across both pdflatex and pandoc call sites.
  • The timeout handling logic (try/except TimeoutExpired, kill, communicate) is duplicated in multiple places; you could factor this into a small helper function to reduce repetition and keep behavior consistent.
  • On timeout you currently just return False or set pdf_created = False; adding some minimal logging or error propagation from the subprocess stderr/stdout would make diagnosing problematic inputs or environments much easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the 30-second timeout value into a shared constant so it’s easier to tune and keep consistent across both pdflatex and pandoc call sites.
- The timeout handling logic (try/except TimeoutExpired, kill, communicate) is duplicated in multiple places; you could factor this into a small helper function to reduce repetition and keep behavior consistent.
- On timeout you currently just return False or set pdf_created = False; adding some minimal logging or error propagation from the subprocess stderr/stdout would make diagnosing problematic inputs or environments much easier.

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