Skip to content

🛡️ Sentinel: [CRITICAL] Fix PDF compilation RCE and timeout vulnerabilities#353

Open
anchapin wants to merge 1 commit into
mainfrom
sentinel-pdf-security-15607158112052287102
Open

🛡️ Sentinel: [CRITICAL] Fix PDF compilation RCE and timeout vulnerabilities#353
anchapin wants to merge 1 commit into
mainfrom
sentinel-pdf-security-15607158112052287102

Conversation

@anchapin

@anchapin anchapin commented Jun 11, 2026

Copy link
Copy Markdown
Owner

🚨 Severity: CRITICAL
💡 Vulnerability: Unsandboxed PDF compilation allowed arbitrary shell command execution (RCE) via LaTeX control sequences injected into templates. The lack of a subprocess timeout also allowed malformed input to stall the compilation indefinitely (DoS).
🎯 Impact: Malicious input or AI hallucinations could lead to complete system compromise via Remote Code Execution, or hang the server thread completely causing Denial of Service.
🔧 Fix: Added -no-shell-escape and --pdf-engine-opt=-no-shell-escape flags to all subprocess.Popen invocations for pdflatex and pandoc in cli/pdf/converter.py and cli/generators/cover_letter_generator.py. Implemented strict 30-second timeouts (process.communicate(timeout=30)) with rigorous cleanup (catching TimeoutExpired, killing the process, and ensuring zombies are cleared) that returns False safely instead of halting the system.
Verification: Verified compilation parameters and timeout behavior via python -m pytest tests/test_pdf_security.py tests/test_cover_letter_security.py. Ran full suite to ensure no regressions. All 681 tests passed.


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

Summary by Sourcery

Harden PDF generation by sandboxing LaTeX compilation and enforcing timeouts to prevent RCE and DoS via untrusted templates.

Bug Fixes:

  • Prevent remote code execution by disabling shell escape when invoking pdflatex and pandoc for PDF generation.
  • Avoid denial-of-service from hung PDF compilations by enforcing a strict timeout and terminating stalled subprocesses.

Documentation:

  • Document the LaTeX PDF compilation RCE and DoS vulnerability, its root cause, and the required mitigations in the Sentinel security notes.

…lities

Added `-no-shell-escape` (pdflatex) and `--pdf-engine-opt=-no-shell-escape` (pandoc) flags to subprocesses in `cli/pdf/converter.py` and `cli/generators/cover_letter_generator.py` to prevent Remote Code Execution via LaTeX `\write18` primitive. Also implemented 30-second timeouts with proper process cleanup (`process.kill()`, secondary `.communicate()`, and early exit) to mitigate Denial of Service (DoS) attacks caused by infinite compilation loops. Added security journal entry for PDF compilation hazards.

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

Copy link
Copy Markdown

Reviewer's Guide

Hardens PDF compilation by disabling LaTeX shell escapes and enforcing timeouts around pdflatex/pandoc subprocesses, plus documenting the vulnerability and mitigation in the Sentinel security log.

Sequence diagram for secured pdflatex PDF compilation with timeout

sequenceDiagram
    participant Caller
    participant Converter as converter._compile_pdflatex
    participant Subprocess as subprocess_Popen
    participant Process as pdflatex_process

    Caller->>Converter: _compile_pdflatex(tex_path, output_path, working_dir)
    Converter->>Subprocess: Popen(["pdflatex","-interaction=nonstopmode","-no-shell-escape",tex_path.name])
    Subprocess-->>Converter: Process
    Converter->>Process: communicate(timeout=30)

    alt [subprocess.TimeoutExpired]
        Converter->>Process: kill()
        Converter->>Process: communicate()
        Converter-->>Caller: False
    else [no timeout]
        Process-->>Converter: stdout, stderr
        Converter-->>Caller: True/False
    end
Loading

File-Level Changes

Change Details Files
Harden pdflatex invocation in cover letter generator against RCE and hangs.
  • Add -no-shell-escape flag to pdflatex command arguments.
  • Wrap process.communicate in a 30-second timeout, killing the process and cleaning up on timeout, and returning False on failure.
  • Keep existing success condition based on return code or output file existence.
cli/generators/cover_letter_generator.py
Harden pandoc-based PDF generation in cover letter generator against RCE and hangs.
  • Extend pandoc invocation with --pdf-engine-opt=-no-shell-escape to disable shell escape in the underlying LaTeX engine.
  • Add 30-second timeout around process.communicate with kill-and-drain cleanup on TimeoutExpired, returning False when compilation stalls.
  • Preserve existing success criteria based on process return code or output file existence.
cli/generators/cover_letter_generator.py
Secure core PDF converter’s pdflatex compilation with shell-escape disabling and timeout handling.
  • Include -no-shell-escape in pdflatex Popen arguments for converter module.
  • Introduce 30-second communicate timeout, with TimeoutExpired handling that kills the process, performs a second communicate to avoid zombies, and returns False to the caller.
cli/pdf/converter.py
Secure core PDF converter’s pandoc flow by disabling shell escape and enforcing a timeout.
  • Augment pandoc command with --pdf-engine-opt=-no-shell-escape in addition to specifying xelatex as the engine.
  • Add communicate(timeout=30) plus TimeoutExpired handling that kills the process, drains pipes, and returns False rather than blocking indefinitely.
cli/pdf/converter.py
Document the newly discovered unsandboxed PDF compilation vulnerability and its mitigations in Sentinel notes.
  • Append a dated section describing the RCE and DoS risk from unsandboxed pdflatex/pandoc usage.
  • Record key learnings about LaTeX toolchain risks with untrusted input and the need for shell-escape disabling and timeouts.
  • Describe prevention patterns including mandatory -no-shell-escape flags and strict subprocess timeout plus cleanup requirements for all PDF compilation paths.
.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 left some high level feedback:

  • The subprocess timeout and kill/cleanup pattern is duplicated across multiple compilation functions; consider extracting a shared helper to ensure consistent behavior and make future hardening (e.g., changing timeout) easier.
  • The 30-second timeout is currently hard-coded in several places; moving this to a single constant or configuration value would make it simpler to tune or override for different environments.
  • You are capturing stdout/stderr from pdflatex/pandoc but never use them on failure or timeout; either log/inspect these streams in the error path for easier debugging, or avoid capturing them to reduce unnecessary resource use.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The subprocess timeout and kill/cleanup pattern is duplicated across multiple compilation functions; consider extracting a shared helper to ensure consistent behavior and make future hardening (e.g., changing timeout) easier.
- The 30-second timeout is currently hard-coded in several places; moving this to a single constant or configuration value would make it simpler to tune or override for different environments.
- You are capturing stdout/stderr from pdflatex/pandoc but never use them on failure or timeout; either log/inspect these streams in the error path for easier debugging, or avoid capturing them to reduce unnecessary resource use.

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