Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix PDF compilation RCE#323

Open
anchapin wants to merge 1 commit into
mainfrom
sentinel-fix-pdf-rce-1962055901658537478
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix PDF compilation RCE#323
anchapin wants to merge 1 commit into
mainfrom
sentinel-fix-pdf-rce-1962055901658537478

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented May 27, 2026

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: The application was executing LaTeX compilers without restricting the shell-escape feature (\write18). It also lacked a subprocess timeout when running pdflatex or pandoc.
🎯 Impact: Maliciously crafted LaTeX input could execute arbitrary shell commands on the host machine leading to full system compromise (RCE). Additionally, malicious documents could induce an infinite compilation loop leading to a Denial of Service (DoS) by resource exhaustion.
πŸ”§ Fix: Passed the -no-shell-escape argument to pdflatex and passed --pdf-engine-opt=-no-shell-escape when utilizing pandoc. Also enforced a timeout=30 argument with process cleanup and graceful failure logic for the subprocess executions. Added journal entry to .jules/sentinel.md outlining the vulnerabilities and preventions.
βœ… Verification: Verified by reviewing the implementation with cat and running tests/test_pdf_security.py via pytest, as well as standard project lint and test checks.


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

Summary by Sourcery

Harden LaTeX-based PDF compilation against remote code execution and denial-of-service by tightening compiler options and subprocess handling.

Bug Fixes:

  • Disable LaTeX shell-escape for both pdflatex and pandoc-based PDF generation to prevent command execution from untrusted documents.
  • Add execution timeouts and cleanup logic around LaTeX compilation subprocesses to avoid hangs and potential resource exhaustion.

Documentation:

  • Document the LaTeX compilation RCE and DoS vulnerabilities, learnings, and mitigations in the Sentinel security journal.

Enforce `-no-shell-escape` for `pdflatex` and `--pdf-engine-opt=-no-shell-escape` for `pandoc` in `cli/pdf/converter.py` and `cli/generators/cover_letter_generator.py` to prevent Remote Code Execution via untrusted LaTeX input. Also added a subprocess timeout to prevent Denial of Service via infinite compilation loops.

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

Reviewer's Guide

Harden LaTeX-based PDF compilation against RCE and DoS by disabling shell-escape and adding timeouts/cleanup around pdflatex and pandoc subprocesses, plus documenting the issue in the Sentinel journal.

Sequence diagram for secure LaTeX PDF compilation with timeout

sequenceDiagram
    participant CoverLetterGenerator as CoverLetterGenerator._compile_pdf
    participant PdfConverter as converter._compile_pdflatex
    participant PandocConverter as converter._compile_pandoc
    participant Subprocess as subprocess

    CoverLetterGenerator->>Subprocess: Popen(["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name])
    Note over CoverLetterGenerator,Subprocess: Primary pdflatex compilation
    CoverLetterGenerator->>Subprocess: communicate(timeout=30)
    alt [pdflatex completes]
        Subprocess-->>CoverLetterGenerator: stdout, stderr (returncode == 0)
        CoverLetterGenerator->>CoverLetterGenerator: set pdf_created = True
    else [TimeoutExpired]
        CoverLetterGenerator->>Subprocess: kill()
        CoverLetterGenerator->>Subprocess: communicate()
        CoverLetterGenerator->>CoverLetterGenerator: pdf_created remains False
    end

    alt [pdf_created is False]
        CoverLetterGenerator->>Subprocess: Popen(["pandoc", tex_path, "-o", output_path, "--pdf-engine=xelatex", "--pdf-engine-opt=-no-shell-escape"])
        Note over CoverLetterGenerator,Subprocess: Fallback pandoc compilation
        CoverLetterGenerator->>Subprocess: communicate(timeout=30)
        alt [pandoc completes]
            Subprocess-->>CoverLetterGenerator: stdout, stderr (returncode == 0)
            CoverLetterGenerator->>CoverLetterGenerator: set pdf_created = True
        else [TimeoutExpired]
            CoverLetterGenerator->>Subprocess: kill()
            CoverLetterGenerator->>Subprocess: communicate()
        end
    end
Loading

File-Level Changes

Change Details Files
Lock down LaTeX compilation subprocesses (pdflatex and pandoc) and add execution timeouts with cleanup to prevent RCE/DoS.
  • Add -no-shell-escape flag to all pdflatex invocations used for PDF compilation.
  • Add --pdf-engine-opt=-no-shell-escape to pandoc invocations that use xelatex as the PDF engine.
  • Wrap subprocess.communicate calls with a 30-second timeout to prevent unbounded compilation.
  • Handle subprocess.TimeoutExpired by killing the process, draining stdio, and failing gracefully (returning False where appropriate).
cli/generators/cover_letter_generator.py
cli/pdf/converter.py
Document the LaTeX compilation RCE/DoS vulnerability and mitigations in the Sentinel journal.
  • Add a dated Sentinel entry describing the root cause (missing -no-shell-escape and timeouts), risk, and mitigations.
  • Highlight best practices for disabling shell-escape and enforcing timeouts with proper subprocess cleanup.
.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 timeout and Popen/communicate/kill logic for pdflatex and pandoc is now duplicated in multiple places; consider extracting a shared helper to reduce repetition and keep future security changes centralized.
  • The 30 second timeout is hard-coded in several calls to communicate; it would be easier to tune and reason about if this were a single constant or configuration value used across all LaTeX compilation paths.
  • The timeout behavior differs slightly between cover_letter_generator._compile_pdf (which falls through and may try pandoc) and converter._compile_pdflatex/_compile_pandoc (which immediately return False); consider aligning these semantics so callers can rely on consistent behavior when a compilation times out.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The timeout and `Popen`/`communicate`/`kill` logic for `pdflatex` and `pandoc` is now duplicated in multiple places; consider extracting a shared helper to reduce repetition and keep future security changes centralized.
- The `30` second timeout is hard-coded in several calls to `communicate`; it would be easier to tune and reason about if this were a single constant or configuration value used across all LaTeX compilation paths.
- The timeout behavior differs slightly between `cover_letter_generator._compile_pdf` (which falls through and may try pandoc) and `converter._compile_pdflatex`/`_compile_pandoc` (which immediately return `False`); consider aligning these semantics so callers can rely on consistent behavior when a compilation times out.

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