Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix PDF compilation RCE and DoS risk#343

Open
anchapin wants to merge 1 commit into
mainfrom
sentinel/pdf-compilation-security-2482042316911710426
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix PDF compilation RCE and DoS risk#343
anchapin wants to merge 1 commit into
mainfrom
sentinel/pdf-compilation-security-2482042316911710426

Conversation

@anchapin

@anchapin anchapin commented Jun 6, 2026

Copy link
Copy Markdown
Owner

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: PDF compilation via subprocess.Popen in cli/pdf/converter.py and cli/generators/cover_letter_generator.py omitted the -no-shell-escape flag for pdflatex and --pdf-engine-opt=-no-shell-escape for the pandoc fallback, allowing arbitrary command execution if malicious LaTeX input was parsed. Furthermore, process.communicate() was called without timeouts, allowing infinite compilation loops (DoS) if bad input caused the compiler to hang.
🎯 Impact: Remote Code Execution (RCE) via \write18 or shell-escape mechanisms inside LaTeX documents, as well as Denial of Service (DoS) due to hanging compiler threads.
πŸ”§ Fix: Added -no-shell-escape to both pdflatex and pandoc execution paths, and added a 30-second timeout with process.kill() cleanup to all process.communicate() calls for PDF compilation.
βœ… Verification: Ran pytest tests successfully. Confirmed flags via manual source code review.


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

Summary by Sourcery

Harden PDF compilation against remote code execution and denial-of-service conditions in LaTeX-based workflows.

Bug Fixes:

  • Disable LaTeX shell escape in both pdflatex and pandoc-based PDF compilation paths to prevent command execution from untrusted input.
  • Add timeouts and cleanup for PDF compilation subprocesses to avoid hangs and potential denial-of-service from stuck compiler processes.

Documentation:

  • Document the PDF compilation RCE and DoS vulnerability, its root cause, and mitigation patterns in the Sentinel security guidance.

Added `-no-shell-escape` flags to `pdflatex` and `pandoc` commands in `cli/pdf/converter.py` and `cli/generators/cover_letter_generator.py` to prevent arbitrary command execution via malicious LaTeX input. Added 30-second timeouts to `process.communicate()` to prevent infinite compilation loops (DoS), implementing process cleanup (`process.kill()`) and returning False upon timeout. Updated `.jules/sentinel.md` with these learnings.

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

Copy link
Copy Markdown

Reviewer's Guide

Locks down LaTeX-based PDF compilation to prevent RCE and DoS by adding no-shell-escape flags for pdflatex/pandoc and enforcing timeouts with cleanup on all PDF compilation subprocesses, plus documenting the incident in the Sentinel security log.

Sequence diagram for secured LaTeX PDF compilation with timeout and no shell escape

sequenceDiagram
    participant Caller
    participant Converter as PdfConverter
    participant Subprocess as subprocess
    participant Process as Popen_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 [TimeoutExpired]
        Converter->>Process: kill()
        Converter->>Process: communicate()
        Converter-->>Caller: return False
    else [No timeout]
        alt [process.returncode == 0 or output_path.exists()]
            Converter-->>Caller: return True
        else [Compilation failed]
            Converter-->>Caller: return False
        end
    end
Loading

File-Level Changes

Change Details Files
Harden pdflatex-based PDF compilation against RCE and DoS in the cover letter generator.
  • Add -no-shell-escape flag to pdflatex invocation to disable shell escape in LaTeX runs.
  • Wrap process.communicate() with a 30-second timeout and kill the process on TimeoutExpired, returning False on timeout failures.
  • Keep stdout/stderr capture intact while ensuring pdf_created is only set when the process succeeds or the output file exists.
cli/generators/cover_letter_generator.py
Harden both pdflatex and pandoc PDF compilation paths in the generic PDF converter.
  • Add -no-shell-escape flag to pdflatex invocation to prevent LaTeX from executing shell commands.
  • Extend pandoc invocation with --pdf-engine-opt=-no-shell-escape so the underlying xelatex engine runs without shell escape.
  • Wrap all process.communicate() calls with a 30-second timeout, killing the process and returning False when compilation hangs.
cli/pdf/converter.py
Record the vulnerability, impact, and remediation details in the Sentinel security history.
  • Append a new critical incident entry describing the missing no-shell-escape flags and absent timeouts for PDF compilation.
  • Document the security learnings around consistent compiler hardening and subprocess timeouts for user-influenced data.
  • Capture prevention guidance for enforcing -no-shell-escape and communicate() timeouts with proper cleanup in future code.
.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 new Popen + communicate(timeout=30) + TimeoutExpired handling is duplicated in multiple places; consider extracting this into a small helper (e.g., run_compiler(cmd, cwd=None)) to keep the timeout/kill/cleanup logic consistent and easier to maintain.
  • The 30 second timeout is currently an inline magic number in several call sites; defining a shared constant (or configuration option) for the PDF compilation timeout would make the behavior clearer and easier to tune across environments.
  • On non-timeout failures you currently ignore stdout/stderr and just return False; consider logging or bubbling up a concise error message so failures in pdflatex/pandoc are easier to diagnose in production without relaxing the security posture.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `Popen` + `communicate(timeout=30)` + `TimeoutExpired` handling is duplicated in multiple places; consider extracting this into a small helper (e.g., `run_compiler(cmd, cwd=None)`) to keep the timeout/kill/cleanup logic consistent and easier to maintain.
- The `30` second timeout is currently an inline magic number in several call sites; defining a shared constant (or configuration option) for the PDF compilation timeout would make the behavior clearer and easier to tune across environments.
- On non-timeout failures you currently ignore `stdout`/`stderr` and just return `False`; consider logging or bubbling up a concise error message so failures in `pdflatex`/`pandoc` are easier to diagnose in production without relaxing the security posture.

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