🛡️ Sentinel: [CRITICAL] Fix LaTeX Subprocess RCE and DoS#350
Conversation
This commit updates the `PDFConverter` class to enforce secure subprocess execution for `pdflatex` and `pandoc`.
Changes:
- Added `-no-shell-escape` to `pdflatex` calls to prevent remote code execution via `\write18{}` macros.
- Added `--pdf-engine-opt=-no-shell-escape` to `pandoc` fallback calls.
- Implemented a strict 30-second timeout on the `subprocess.communicate()` calls.
- Added proper process cleanup logic (catch `TimeoutExpired`, `process.kill()`, and reap zombie process via a second `communicate()`).
- Added tests to `tests/test_pdf_security.py` to verify the subprocess arguments and timeout handling.
Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's GuideHardened the PDF conversion pipeline against LaTeX-based RCE and DoS by enforcing no-shell-escape flags, adding subprocess timeouts with proper cleanup, and backstopping the behavior with targeted unit tests and security documentation updates. Sequence diagram for secured LaTeX PDF compilation with timeout and no-shell-escapesequenceDiagram
participant PDFConverter as _compile_pdflatex
participant Subprocess as subprocess
participant Proc as pdflatex_process
PDFConverter->>Subprocess: Popen(["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name])
Subprocess-->>PDFConverter: Proc
PDFConverter->>Proc: communicate(timeout=30)
alt subprocess completes in time
Proc-->>PDFConverter: stdout, stderr (returncode == 0)
PDFConverter-->>PDFConverter: return True
else TimeoutExpired
Proc-->>PDFConverter: subprocess.TimeoutExpired
PDFConverter->>Proc: kill()
PDFConverter->>Proc: communicate()
Proc-->>PDFConverter: stdout, stderr
PDFConverter-->>PDFConverter: return False
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The timeout and kill/communicate logic is duplicated in both
_compile_pdflatexand_compile_pandoc; consider extracting this into a small helper to centralize the pattern and avoid divergence in future changes. - The 30-second timeout value is hard-coded in multiple places (implementation and tests); promoting it to a named constant in the converter and referencing that in tests would make future tuning easier and less error-prone.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The timeout and kill/communicate logic is duplicated in both `_compile_pdflatex` and `_compile_pandoc`; consider extracting this into a small helper to centralize the pattern and avoid divergence in future changes.
- The 30-second timeout value is hard-coded in multiple places (implementation and tests); promoting it to a named constant in the converter and referencing that in tests would make future tuning easier and less error-prone.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
🚨 Severity: CRITICAL
💡 Vulnerability: The
PDFConverterclass executedpdflatexandpandocwithout the-no-shell-escapeflags, allowing potential remote code execution (RCE) via\write18{}macros if an attacker controlled the LaTeX input. Additionally, the compilation subprocess did not have a timeout, allowing malicious LaTeX input (e.g. infinite loops via\def) to cause Denial of Service (DoS) by hanging the application thread indefinitely.🎯 Impact: An attacker who can influence the LaTeX template could execute arbitrary commands on the server running the application (RCE). They could also hang the application indefinitely by providing inputs that cause the LaTeX compiler to spin in an infinite loop (DoS).
🔧 Fix: Enforced the
-no-shell-escapeflag forpdflatexdirectly and forpandocvia--pdf-engine-opt=-no-shell-escape. Also enforced a strict 30-second timeout on thesubprocess.communicate()calls, accompanied by proper zombie process reaping (process.kill()followed bycommunicate()).✅ Verification: Ensure tests pass locally by running
python -m pytest tests/test_pdf_security.py. Review thecli/pdf/converter.pyfile to verify the subprocess parameters and exception handling blocks.PR created automatically by Jules for task 2493027765909998490 started by @anchapin
Summary by Sourcery
Harden LaTeX-based PDF generation to prevent RCE and DoS via unsafe subprocess execution.
Bug Fixes:
Tests: