π‘οΈ Sentinel: [CRITICAL] Fix command injection in PDF compilation#270
π‘οΈ Sentinel: [CRITICAL] Fix command injection in PDF compilation#270
Conversation
Co-authored-by: anchapin <[email protected]>
|
π 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 GuideHarden PDF compilation against command injection and DoS by disabling shell escape in pdflatex/pandoc and enforcing a 30s timeout on all LaTeX compilation subprocesses. Sequence diagram for hardened PDF compilation with timeout and no shell escapesequenceDiagram
title Hardened PDF compilation flow with timeout and no shell escape
actor User
participant CLIApp
participant PDFCompiler
participant Subprocess
participant PdfEngine
User->>CLIApp: request PDF generation
CLIApp->>PDFCompiler: compile(tex_content, output_path)
rect rgb(230,230,255)
PDFCompiler->>Subprocess: Popen([pdflatex|pandoc, -interaction=nonstopmode, -no-shell-escape,...])
Subprocess->>PdfEngine: start process with args
PdfEngine-->>Subprocess: running
alt completes within 30s
PDFCompiler->>Subprocess: communicate(timeout=30)
Subprocess-->>PDFCompiler: stdout, stderr
PDFCompiler->>PDFCompiler: check returncode or output_path.exists()
alt success
PDFCompiler-->>CLIApp: True (PDF created)
CLIApp-->>User: return generated PDF
else failure
PDFCompiler-->>CLIApp: False (compilation failed)
CLIApp-->>User: report compilation error
end
else exceeds 30s
PDFCompiler->>Subprocess: communicate(timeout=30)
Subprocess-->>PDFCompiler: TimeoutExpired exception
PDFCompiler->>Subprocess: kill()
PDFCompiler->>Subprocess: communicate()
Subprocess-->>PDFCompiler: stdout, stderr
PDFCompiler-->>CLIApp: raise RuntimeError
CLIApp-->>User: report PDF compilation timed out
end
end
Updated class diagram for PDF compilation helpers with security hardeningclassDiagram
class CoverLetterGenerator {
+_compile_pdf(output_path, tex_content) bool
}
class PDFConverter {
+_compile_pdflatex(tex_path, output_path, working_dir) bool
+_compile_pandoc(tex_path, output_path, working_dir) bool
}
class SubprocessModule {
+Popen(args, stdout, stderr, cwd) Process
}
class Process {
+communicate(timeout) stdout_stderr
+kill() void
+returncode int
}
class PdfLatexEngine {
+exec(-interaction=nonstopmode, -no-shell-escape, tex_name) void
}
class PandocEngine {
+exec(tex_path, output_path, --pdf-engine=xelatex, --pdf-engine-opt=-no-shell-escape) void
}
CoverLetterGenerator ..> SubprocessModule : uses
PDFConverter ..> SubprocessModule : uses
SubprocessModule ..> Process : returns
Process ..> PdfLatexEngine : runs
Process ..> PandocEngine : runs
CoverLetterGenerator ..> PdfLatexEngine : compiles
CoverLetterGenerator ..> PandocEngine : fallback
PDFConverter ..> PdfLatexEngine : _compile_pdflatex
PDFConverter ..> PandocEngine : _compile_pandoc
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 timeout handling logic for
pdflatexandpandocis duplicated in multiple places; consider extracting a small helper (e.g.,run_with_timeout(cmd, cwd, timeout=30)) to centralize process execution, timeout, and error behavior. - On
RuntimeError("PDF compilation timed out"), stdout/stderr are currently discarded; capturing and attaching stderr (or at least logging it) would make diagnosing misconfigurations or unexpected hangs much easier while keeping the call sites unchanged.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new timeout handling logic for `pdflatex` and `pandoc` is duplicated in multiple places; consider extracting a small helper (e.g., `run_with_timeout(cmd, cwd, timeout=30)`) to centralize process execution, timeout, and error behavior.
- On `RuntimeError("PDF compilation timed out")`, stdout/stderr are currently discarded; capturing and attaching stderr (or at least logging it) would make diagnosing misconfigurations or unexpected hangs much easier while keeping the call sites unchanged.Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
π¨ Severity: CRITICAL
π‘ Vulnerability: Command injection/Remote Code Execution (RCE) via
pdflatexandpandocduring PDF compilation inPDFConverterandCoverLetterGenerator.π― Impact: Malicious user input or hallucinated LaTeX control characters could inject arbitrary shell commands.
π§ Fix: Add
-no-shell-escapeflag topdflatexand--pdf-engine-opt=-no-shell-escapetopandoc. Addedtimeout=30tosubprocess.communicate()calls to prevent DoS.β Verification: Ran
tests/test_pdf_security.pyto ensure flags and timeout behavior function safely. All tests pass and linter passes.PR created automatically by Jules for task 10565898894670016090 started by @anchapin
Summary by Sourcery
Harden PDF compilation against command injection and long-running processes by enforcing shell-escape disabling and adding timeouts to external LaTeX/Pandoc calls.
Bug Fixes: