Skip to content

🛡️ Sentinel: [CRITICAL] Fix subprocess compilation RCE & DoS vulnerabilities#315

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

🛡️ Sentinel: [CRITICAL] Fix subprocess compilation RCE & DoS vulnerabilities#315
anchapin wants to merge 1 commit into
mainfrom
sentinel-pdf-rce-dos-fix-10899137613891022970

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented May 22, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: The application was calling pdflatex and pandoc in cover_letter_generator.py and converter.py without -no-shell-escape flags and without tracking subprocess timeouts. Malicious or compromised LaTeX input containing shell-escape commands (\write18) could execute arbitrary system commands (Remote Code Execution) during the compilation step. Furthermore, compilation could hang indefinitely on invalid inputs, causing a Denial of Service (DoS) zombie process.
🎯 Impact: Potential Remote Code Execution (RCE) and Denial of Service (DoS) when generating Cover Letters or converting PDFs.
🔧 Fix: Enforced -no-shell-escape flag for pdflatex and --pdf-engine-opt=-no-shell-escape for pandoc. Wrapped process.communicate() in explicit try-catch blocks with timeout=30, correctly catching subprocess.TimeoutExpired, executing process.kill(), and repeating process.communicate() to prevent double-free issues and clean up zombie processes.
Verification: Tests passing (python -m pytest tests/test_pdf_security.py). Manual code review confirms RCE paths closed and DoS zombie process prevention is handled correctly.


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

Summary by Sourcery

Harden PDF compilation against RCE and DoS by tightening LaTeX subprocess invocation and documenting the security learnings.

Bug Fixes:

  • Disable LaTeX shell escapes for pdflatex and pandoc PDF generation to prevent command execution via malicious input.
  • Add timeouts, cleanup, and explicit error handling around PDF compilation subprocesses to avoid hangs and zombie processes.

Documentation:

  • Extend the Sentinel security log with a new entry describing the subprocess PDF compilation vulnerabilities, mitigations, and best practices.

…ilities

Enforce `-no-shell-escape` flags and explicit timeouts for `pdflatex` and `pandoc` compilation subprocesses in `cover_letter_generator.py` and `converter.py`.

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

Reviewer's Guide

Harden subprocess LaTeX/PDF compilation against RCE and DoS by disabling shell escape for pdflatex/pandoc and adding bounded, well‑cleaned timeouts for all compilation and availability checks, and record this as a new Sentinel security note.

Sequence diagram for secure PDF compilation subprocess handling

sequenceDiagram
    participant Caller as CoverLetterGenerator_or_Converter
    participant Subprocess as subprocess
    participant Process as Popen_process

    Caller->>Subprocess: Popen(pdflatex_or_pandoc_args)
    Subprocess-->>Caller: Process

    Caller->>Process: communicate(timeout=30)
    alt TimeoutExpired
        Process-->>Caller: subprocess.TimeoutExpired
        Caller->>Process: kill()
        Caller->>Process: communicate()
        Caller-->>Caller: raise RuntimeError("PDF compilation timed out")
    else Completed
        Process-->>Caller: stdout, stderr
        Caller-->>Caller: check returncode or output_path.exists()
    end
Loading

File-Level Changes

Change Details Files
Secure pdflatex compilation in the generic PDF converter against RCE and long‑running processes.
  • Add -no-shell-escape flag to pdflatex invocation to prevent LaTeX shell escapes
  • Wrap process.communicate() with a 30-second timeout when compiling, catching subprocess.TimeoutExpired
  • On timeout, kill the pdflatex process, drain stdout/stderr with a second communicate(), and raise a RuntimeError signaling compilation timeout
cli/pdf/converter.py
Secure pandoc-based PDF compilation in the generic PDF converter against RCE and long‑running processes.
  • Extend pandoc invocation to pass --pdf-engine-opt=-no-shell-escape to the xelatex engine
  • Wrap pandoc process.communicate() with a 30-second timeout and handle subprocess.TimeoutExpired by killing the process, draining output, and raising a RuntimeError
cli/pdf/converter.py
Ensure pdflatex and pandoc availability checks cannot hang indefinitely.
  • Wrap pdflatex availability check communicate() in a 10-second timeout; on timeout, kill the process and call communicate() again before returning status
  • Apply the same 10-second timeout, kill, and cleanup behavior to the pandoc availability check
cli/pdf/converter.py
Harden CoverLetter PDF compilation paths against RCE and DoS in the generator.
  • Add -no-shell-escape flag to pdflatex invocation in cover letter PDF compilation
  • Add --pdf-engine-opt=-no-shell-escape to the pandoc fallback invocation
  • For both pdflatex and pandoc, wrap process.communicate() with a 30-second timeout; on subprocess.TimeoutExpired, kill the process, run a second communicate() to drain pipes, and raise RuntimeError("PDF compilation timed out")
cli/generators/cover_letter_generator.py
Document the new subprocess PDF compilation security hardening in the Sentinel security log.
  • Append a dated entry describing the previous RCE/DoS risks from pdflatex/pandoc usage without -no-shell-escape and timeouts
  • Record the new mitigation pattern: always disable shell escape, set explicit timeouts, kill on timeout, and re-run communicate() to avoid zombie processes and double-free issues
.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 new subprocess invocations for pdflatex/pandoc (including flags, timeouts, and timeout handling) are duplicated across converter.py and cover_letter_generator.py; consider extracting a shared helper to centralize this security-sensitive logic and reduce the risk of future drift.
  • Raising a generic RuntimeError("PDF compilation timed out") on timeout changes the observable behavior of these paths; consider using a dedicated exception type or wrapping with additional context (e.g., which engine and source path) so callers and logs can distinguish timeout failures from other runtime errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new subprocess invocations for pdflatex/pandoc (including flags, timeouts, and timeout handling) are duplicated across converter.py and cover_letter_generator.py; consider extracting a shared helper to centralize this security-sensitive logic and reduce the risk of future drift.
- Raising a generic RuntimeError("PDF compilation timed out") on timeout changes the observable behavior of these paths; consider using a dedicated exception type or wrapping with additional context (e.g., which engine and source path) so callers and logs can distinguish timeout failures from other runtime errors.

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