Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix RCE and DoS vulnerabilities in PDF compilation#384

Open
anchapin wants to merge 2 commits into
mainfrom
sentinel/fix-pdf-rce-9649511856481661638
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix RCE and DoS vulnerabilities in PDF compilation#384
anchapin wants to merge 2 commits into
mainfrom
sentinel/fix-pdf-rce-9649511856481661638

Conversation

@anchapin

@anchapin anchapin commented Jun 29, 2026

Copy link
Copy Markdown
Owner
  • 🚨 Severity: CRITICAL
  • πŸ’‘ Vulnerability: RCE via LaTeX shell escapes and DoS via missing subprocess timeouts
  • 🎯 Impact: Attackers could execute arbitrary commands via crafted LaTeX inputs or consume server resources
  • πŸ”§ Fix: Added -no-shell-escape flags to pdflatex and pandoc calls, and added 30-second timeouts with cleanup
  • βœ… Verification: Added timeout and argument validation tests in test_pdf_security.py

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

Summary by Sourcery

Harden PDF compilation against RCE and DoS by constraining LaTeX and pandoc subprocess execution.

Bug Fixes:

  • Prevent remote code execution in pdflatex and pandoc-based PDF generation by disabling LaTeX shell escapes.
  • Mitigate denial-of-service risks in PDF compilation by enforcing subprocess timeouts and cleanup.

Enhancements:

  • Add security-focused unit tests covering pdflatex and pandoc arguments, timeouts, and fallback behavior in PDF converters and cover letter generation.
  • Document the PDF compilation security posture and mitigation strategies in the Sentinel security log.

Documentation:

  • Update .jules/sentinel.md with a new entry describing the PDF compilation RCE and DoS vulnerabilities and their mitigations.

Tests:

  • Extend test_pdf_security to verify no-shell-escape flags, timeout handling, and failure modes for pdflatex and pandoc in both PDFConverter and CoverLetterGenerator.

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 commented Jun 29, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR hardens PDF compilation against RCE and DoS by disabling LaTeX shell escapes and enforcing 30s timeouts with cleanup on all pdflatex/pandoc subprocess calls, and adds tests to validate the new behavior.

Sequence diagram for secured PDF compilation with pdflatex and pandoc

sequenceDiagram
    participant CoverLetterGenerator
    participant subprocess
    participant pdflatex_process
    participant pandoc_process

    CoverLetterGenerator->>subprocess: Popen(pdflatex, -interaction=nonstopmode, -no-shell-escape)
    subprocess-->>CoverLetterGenerator: pdflatex_process

    CoverLetterGenerator->>pdflatex_process: communicate(timeout=30)
    alt [TimeoutExpired]
        CoverLetterGenerator->>pdflatex_process: kill()
        CoverLetterGenerator->>pdflatex_process: communicate()
        CoverLetterGenerator-->>CoverLetterGenerator: pdf_created = False
    else [pdflatex returns success or output_path exists]
        pdflatex_process-->>CoverLetterGenerator: returncode, stdout, stderr
        CoverLetterGenerator-->>CoverLetterGenerator: pdf_created = True
    else [pdflatex fails]
        CoverLetterGenerator->>subprocess: Popen(pandoc, --pdf-engine=xelatex, --pdf-engine-opt=-no-shell-escape)
        subprocess-->>CoverLetterGenerator: pandoc_process
        CoverLetterGenerator->>pandoc_process: communicate(timeout=30)
        alt [TimeoutExpired]
            CoverLetterGenerator->>pandoc_process: kill()
            CoverLetterGenerator->>pandoc_process: communicate()
            CoverLetterGenerator-->>CoverLetterGenerator: pdf_created = False
        else [pandoc returns success or output_path exists]
            pandoc_process-->>CoverLetterGenerator: returncode, stdout, stderr
            CoverLetterGenerator-->>CoverLetterGenerator: pdf_created = True
        end
    end
Loading

File-Level Changes

Change Details Files
Hardened pdflatex and pandoc subprocess invocations in the generic PDF converter to prevent RCE and long‑running compilations.
  • Added -no-shell-escape to pdflatex invocation arguments.
  • Expanded pandoc invocation to include --pdf-engine-opt=-no-shell-escape while keeping xelatex as the engine.
  • Wrapped subprocess.communicate calls with 30-second timeouts and kill/cleanup on TimeoutExpired for both tools.
  • Ensured compile functions return False when compilation times out or fails after timeout handling.
cli/pdf/converter.py
Applied the same security measures to the cover letter PDF compilation path, including fallback from pdflatex to pandoc.
  • Augmented pdflatex command with -no-shell-escape and timeout-based communicate, killing the process on TimeoutExpired and short‑circuiting with False.
  • Updated pandoc fallback command to include --pdf-engine-opt=-no-shell-escape and wrapped communicate with timeout and cleanup, only marking success on zero exit or existing output file.
  • Kept existing error handling for CalledProcessError/FileNotFoundError while integrating the new control flow.
cli/generators/cover_letter_generator.py
Added focused security regression tests to verify arguments and timeout behavior for both PDFConverter and CoverLetterGenerator.
  • Introduced a MockConfig helper for CoverLetterGenerator tests to satisfy configuration dependencies.
  • Added tests that simulate TimeoutExpired for pdflatex and pandoc and assert kill/communicate with timeout=30 and False result.
  • Added argument validation tests ensuring -no-shell-escape for pdflatex and --pdf-engine-opt=-no-shell-escape with xelatex for pandoc in both converter and cover letter generator flows.
  • Added tests for cover letter pdflatex failure and pandoc fallback paths to validate timeout handling and argument wiring.
tests/test_pdf_security.py
Documented the new Sentinel security finding related to LaTeX PDF compilation.
  • Appended a Sentinel entry describing the RCE and DoS vulnerabilities and the mitigation pattern to the security log.
.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

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

Hey - I've found 1 issue, and left some high level feedback:

  • The 30-second timeout and kill/cleanup logic for pdflatex/pandoc is duplicated across PDFConverter and CoverLetterGenerator; consider extracting a shared helper to centralize and standardize this security-sensitive subprocess handling.
  • The hard-coded 30-second timeout value is repeated in several places; defining a single configuration or module-level constant for the PDF compilation timeout would make future tuning easier and reduce the chance of inconsistent behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The 30-second timeout and kill/cleanup logic for pdflatex/pandoc is duplicated across PDFConverter and CoverLetterGenerator; consider extracting a shared helper to centralize and standardize this security-sensitive subprocess handling.
- The hard-coded 30-second timeout value is repeated in several places; defining a single configuration or module-level constant for the PDF compilation timeout would make future tuning easier and reduce the chance of inconsistent behavior.

## Individual Comments

### Comment 1
<location path="cli/pdf/converter.py" line_range="101" />
<code_context>
+
             if process.returncode == 0 or output_path.exists():
                 pdf_created = True
         except (subprocess.CalledProcessError, FileNotFoundError):
</code_context>
<issue_to_address>
**suggestion:** Remove `CalledProcessError` from this exception list when using `Popen`.

`subprocess.Popen` with `communicate()` does not raise `CalledProcessError`, so including it here implies an impossible failure mode. Removing it will make the actual error handling path more accurate and easier to understand.
</issue_to_address>

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.

Comment thread cli/pdf/converter.py
except subprocess.TimeoutExpired:
process.kill()
process.communicate()
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Remove CalledProcessError from this exception list when using Popen.

subprocess.Popen with communicate() does not raise CalledProcessError, so including it here implies an impossible failure mode. Removing it will make the actual error handling path more accurate and easier to understand.

Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
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