π‘οΈ Sentinel: [CRITICAL] Fix RCE in PDF compilation#345
Conversation
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 PDF compilation against RCE and DoS by enforcing LaTeX shell-escape restrictions for both pdflatex and pandoc, and by adding timeouts with safe teardown for all long-running compilation subprocesses, plus documenting the new Sentinel security requirement. Sequence diagram for secured pdflatex PDF compilation with timeoutsequenceDiagram
participant Converter as PdfConverter
participant Subprocess as subprocess
participant Pdflatex as pdflatex_process
Converter->>Subprocess: Popen(["pdflatex", "-interaction=nonstopmode", "-no-shell-escape", tex_path.name])
Subprocess-->>Converter: Pdflatex (process)
Converter->>Pdflatex: communicate(timeout=30)
alt [process finishes before timeout]
Pdflatex-->>Converter: stdout, stderr
alt [process.returncode == 0 or output_path.exists()]
Converter-->>Converter: return True
else [compile failed]
Converter-->>Converter: return False
end
else [subprocess.TimeoutExpired]
Converter->>Pdflatex: kill()
Converter->>Pdflatex: communicate()
Pdflatex-->>Converter: stdout, stderr
Converter-->>Converter: 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 new subprocess timeout and kill/cleanup logic is duplicated in multiple places; consider extracting a small helper (e.g.,
run_with_timeout(cmd, cwd=None, timeout=30) -> (returncode, stdout, stderr)) to centralize behavior and make future changes less error-prone. - The 30-second timeout is currently hard-coded in several calls; it may be useful to make this configurable (via a constant or parameter) so different environments or workloads can tune the compilation time limit without code changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new subprocess timeout and kill/cleanup logic is duplicated in multiple places; consider extracting a small helper (e.g., `run_with_timeout(cmd, cwd=None, timeout=30) -> (returncode, stdout, stderr)`) to centralize behavior and make future changes less error-prone.
- The 30-second timeout is currently hard-coded in several calls; it may be useful to make this configurable (via a constant or parameter) so different environments or workloads can tune the compilation time limit without code changes.Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
π¨ Severity: CRITICAL
π‘ Vulnerability: PDF compilation via
pdflatexandpandoccan execute arbitrary commands if-no-shell-escapeis not specified, leading to potential Remote Code Execution (RCE) from untrusted input. Additionally, lack of subprocess timeouts could lead to DoS from hanging compilations.π― Impact: An attacker could potentially gain unauthorized code execution privileges on the server or cause a Denial of Service by supplying malformed LaTeX input.
π§ Fix: Added
-no-shell-escapeflag (forpdflatex) and--pdf-engine-opt=-no-shell-escape(forpandoc) to subprocess calls incli/generators/cover_letter_generator.pyandcli/pdf/converter.py. Added a 30-second timeout to.communicate()calls with proper process cleanup (catchingTimeoutExpired, killing the process, and flushing pipes) to mitigate DoS risks.β Verification: Ran
pytest tests/test_cover_letter_generator.py tests/test_cover_letter_security.py tests/test_pdf_security.pyand fullpython -m pytesttest suite successfully. Evaluated and approved by code review.PR created automatically by Jules for task 1025421589653301781 started by @anchapin
Summary by Sourcery
Mitigate security risks in LaTeX-based PDF generation by hardening external compilation subprocesses and documenting the RCE class of issues.
Bug Fixes:
Enhancements:
Documentation: