Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Remote Code Execution in PDF Generation#275

Open
anchapin wants to merge 1 commit intomainfrom
sentinel-fix-pdf-rce-7659911145396587821
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix Remote Code Execution in PDF Generation#275
anchapin wants to merge 1 commit intomainfrom
sentinel-fix-pdf-rce-7659911145396587821

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented Apr 30, 2026

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: Remote Code Execution (RCE) and Denial of Service (DoS) in PDF Generation. pdflatex and pandoc were invoked without the -no-shell-escape flag or a process timeout in cli/pdf/converter.py and cli/generators/cover_letter_generator.py. This allows malicious LaTeX input (e.g. \write18{...}) to execute arbitrary shell commands on the host system.
🎯 Impact: Complete system compromise via arbitrary command execution if an attacker can control the LaTeX input. Potential DoS by causing an infinite compilation loop.
πŸ”§ Fix: Added -no-shell-escape to pdflatex and --pdf-engine-opt=-no-shell-escape to pandoc invocations. Added a 30-second timeout to all process.communicate() calls with proper error handling and process termination.
βœ… Verification: Verified by reviewing the code changes, ensuring all subprocess interactions correctly handle timeouts and cleanups, and executing the test suite successfully. Evaluated test cases confirming the pdflatex flag inclusion and timeout logic. Also appended learning to .jules/sentinel.md.


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

Summary by Sourcery

Harden PDF generation against remote code execution and hangs by securing LaTeX subprocess invocations.

Bug Fixes:

  • Prevent remote code execution in PDF generation by disabling LaTeX shell escape in pdflatex and pandoc calls.
  • Avoid potential denial-of-service in PDF generation by enforcing a timeout and cleanup on LaTeX subprocess execution.

Documentation:

  • Document the LaTeX-based RCE and DoS vulnerability, its root cause, and the standardized prevention measures in the Sentinel security learnings log.

Adds -no-shell-escape flags and 30-second timeouts to pdflatex and
pandoc subprocess invocations in cover letter generation and pdf conversion
modules. This prevents arbitrary code execution and infinite compilation
loops when generating PDFs from user input.

Co-authored-by: anchapin <[email protected]>
@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 30, 2026

Reviewer's Guide

Hardened LaTeX-to-PDF generation by disabling shell escapes for pdflatex/pandoc and adding 30s timeouts with cleanup to all PDF compilation subprocesses, plus documenting the incident in the Sentinel playbook.

Sequence diagram for hardened cover letter PDF compilation with timeout and fallback

sequenceDiagram
    participant CoverLetterGenerator
    participant PdflatexProcess
    participant PandocProcess

    CoverLetterGenerator->>PdflatexProcess: Popen pdflatex -interaction=nonstopmode -no-shell-escape
    alt pdflatex completes within 30s
        PdflatexProcess-->>CoverLetterGenerator: communicate timeout=30
        alt returncode == 0 or output_path exists
            CoverLetterGenerator->>CoverLetterGenerator: set pdf_created true
        else pdflatex nonzero exit
            CoverLetterGenerator->>CoverLetterGenerator: raise CalledProcessError
            CoverLetterGenerator->>PandocProcess: Popen pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape
            alt pandoc completes within 30s
                PandocProcess-->>CoverLetterGenerator: communicate timeout=30
                alt returncode == 0 or output_path exists
                    CoverLetterGenerator->>CoverLetterGenerator: set pdf_created true
                else pandoc nonzero exit
                    CoverLetterGenerator->>CoverLetterGenerator: handle failure pdf_created remains false
                end
            else pandoc TimeoutExpired
                CoverLetterGenerator->>PandocProcess: kill
                PandocProcess-->>CoverLetterGenerator: communicate drain
                CoverLetterGenerator->>CoverLetterGenerator: handle failure pdf_created remains false
            end
        end
    else pdflatex TimeoutExpired
        CoverLetterGenerator->>PdflatexProcess: kill
        PdflatexProcess-->>CoverLetterGenerator: communicate drain
        CoverLetterGenerator->>CoverLetterGenerator: raise CalledProcessError to trigger fallback
        CoverLetterGenerator->>PandocProcess: Popen pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape
        alt pandoc completes within 30s
            PandocProcess-->>CoverLetterGenerator: communicate timeout=30
            alt returncode == 0 or output_path exists
                CoverLetterGenerator->>CoverLetterGenerator: set pdf_created true
            else pandoc nonzero exit
                CoverLetterGenerator->>CoverLetterGenerator: handle failure pdf_created remains false
            end
        else pandoc TimeoutExpired
            CoverLetterGenerator->>PandocProcess: kill
            PandocProcess-->>CoverLetterGenerator: communicate drain
            CoverLetterGenerator->>CoverLetterGenerator: handle failure pdf_created remains false
        end
    end
Loading

Flow diagram for secured LaTeX PDF compilation subprocesses in converter

flowchart TD
    Start[[Start _compile_pdflatex or _compile_pandoc]]
    A[Create subprocess with security flags
pdflatex -interaction=nonstopmode -no-shell-escape
or
pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape]
    B{communicate timeout=30
TimeoutExpired?}
    C[Kill process]
    D[Drain output with communicate]
    E[Return False to caller]
    F{process returncode == 0
or output_path exists?}
    G[Return True to caller]
    H[Raise CalledProcessError or handle as failure]

    Start --> A --> B
    B -- Yes --> C --> D --> E
    B -- No --> F
    F -- Yes --> G
    F -- No --> H --> E
Loading

File-Level Changes

Change Details Files
Disable LaTeX shell command execution for all pdflatex/pandoc invocations in PDF generation paths.
  • Add -no-shell-escape flag to pdflatex command used in cover letter PDF compilation.
  • Add --pdf-engine-opt=-no-shell-escape to the pandoc-based PDF fallback in the cover letter generator.
  • Add -no-shell-escape to the pdflatex invocation in the generic PDF converter.
  • Add --pdf-engine-opt=-no-shell-escape to the pandoc invocation in the generic PDF converter.
cli/generators/cover_letter_generator.py
cli/pdf/converter.py
Introduce bounded execution time and cleanup for LaTeX compilation subprocesses to mitigate DoS and hanging processes.
  • Wrap process.communicate calls with a 30-second timeout for pdflatex in the cover letter generator and raise a CalledProcessError on timeout to trigger the pandoc fallback.
  • Wrap pandoc communicate in the cover letter generator with a 30-second timeout and treat timeouts as failures handled by existing error logic.
  • In the generic PDF converter, add 30-second timeouts around both pdflatex and pandoc communicate calls, killing the process and returning False on timeout.
  • Ensure all timeout handlers call process.kill and a final communicate to avoid zombies before signaling failure.
cli/generators/cover_letter_generator.py
cli/pdf/converter.py
Document the RCE/DoS incident and remediation in the Sentinel security notes.
  • Append a new dated section describing the LaTeX RCE/DoS vulnerability, its root cause, and the fix.
  • Record learnings about consistent application of security flags and timeouts for subprocess calls.
  • Capture prevention guidance to always enforce -no-shell-escape/--pdf-engine-opt=-no-shell-escape and timeouts for risky external processes.
.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 subprocess timeout/kill/communicate pattern is duplicated across multiple call sites; consider extracting a small helper (e.g., run_with_timeout(cmd, cwd=None, timeout=30) -> CompletedProcess|None) to centralize the behavior and avoid drift in future changes.
  • Right now a timeout is treated the same as other CalledProcessError paths; if distinguishing timeouts from regular compilation failures would be useful, consider surfacing that via a specific exception type, return value, or log message so callers can react differently (e.g., inform users vs. silently falling back).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The subprocess timeout/kill/communicate pattern is duplicated across multiple call sites; consider extracting a small helper (e.g., `run_with_timeout(cmd, cwd=None, timeout=30) -> CompletedProcess|None`) to centralize the behavior and avoid drift in future changes.
- Right now a timeout is treated the same as other `CalledProcessError` paths; if distinguishing timeouts from regular compilation failures would be useful, consider surfacing that via a specific exception type, return value, or log message so callers can react differently (e.g., inform users vs. silently falling back).

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