π‘οΈ Sentinel: [CRITICAL] Fix missing -no-shell-escape flag and timeout in PDF generation#289
π‘οΈ Sentinel: [CRITICAL] Fix missing -no-shell-escape flag and timeout in PDF generation#289
Conversation
β¦ in PDF generation Added `-no-shell-escape` flag to pdflatex and pandoc commands in `cli/generators/cover_letter_generator.py` and `cli/pdf/converter.py` to prevent Remote Code Execution (RCE) via malicious LaTeX input. Added 30-second timeouts to the subprocess.communicate() calls to prevent infinite loops causing Denial of Service (DoS), matching the existing implementation in `cli/generators/template.py`. 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 GuideAdds hardened PDF generation by enforcing no-shell-escape in LaTeX/pandoc commands and introducing 30s timeouts with explicit timeout handling for both the cover letter generator and generic PDF converter. Sequence diagram for hardened cover letter PDF compilationsequenceDiagram
actor User
participant CoverLetterGenerator
participant Filesystem
participant Subprocess
User->>CoverLetterGenerator: request_cover_letter_pdf(tex_content, output_path)
CoverLetterGenerator->>Filesystem: write_tex_file(tex_content)
Filesystem-->>CoverLetterGenerator: tex_path
CoverLetterGenerator->>Subprocess: Popen(pdflatex -interaction=nonstopmode -no-shell-escape tex_path.name)
alt within_30_seconds
Subprocess-->>CoverLetterGenerator: communicate(timeout=30)
alt pdflatex_success_or_output_exists
CoverLetterGenerator-->>User: return True (pdf_created)
else pdflatex_failure
CoverLetterGenerator->>Subprocess: Popen(pandoc --pdf-engine=xelatex --pdf-engine-opt=-no-shell-escape)
alt within_30_seconds
Subprocess-->>CoverLetterGenerator: communicate(timeout=30)
alt pandoc_success_or_output_exists
CoverLetterGenerator-->>User: return True (pdf_created)
else pandoc_failure
CoverLetterGenerator-->>User: return False
end
else pandoc_timeout
Subprocess->>Subprocess: kill()
Subprocess-->>CoverLetterGenerator: communicate()
CoverLetterGenerator-->>User: raise RuntimeError(PDF compilation timed out)
end
end
else pdflatex_timeout
Subprocess->>Subprocess: kill()
Subprocess-->>CoverLetterGenerator: communicate()
CoverLetterGenerator-->>User: raise RuntimeError(PDF compilation timed out)
end
Flow diagram for hardened generic PDF converter compilationflowchart TD
A[start_compile_pdf] --> B[run_pdflatex_with_no_shell_escape]
B --> C[communicate timeout 30s]
C --> D{pdflatex_timed_out}
D -- yes --> E[kill process]
E --> F[communicate drain_pipes]
F --> G[return False]
D -- no --> H{pdflatex_success_or_output_exists}
H -- yes --> I[return True]
H -- no --> J[run_pandoc_with_no_shell_escape]
J --> K[communicate timeout 30s]
K --> L{pandoc_timed_out}
L -- yes --> M[kill process]
M --> N[communicate drain_pipes]
N --> O[return False]
L -- no --> P{pandoc_success_or_output_exists}
P -- yes --> Q[return True]
P -- no --> R[return False]
File-Level Changes
Possibly linked issues
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 handling logic for pdflatex/pandoc is duplicated in multiple places; consider extracting a shared helper that encapsulates the 30s timeout, process.kill(), and communicate() behavior so it stays consistent and easier to adjust later.
- On timeout, cover_letter_generator raises RuntimeError while converter returns False, which creates different error semantics for similar failures; it may be worth aligning these behaviors or clearly documenting the difference so callers can handle them consistently.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The timeout handling logic for pdflatex/pandoc is duplicated in multiple places; consider extracting a shared helper that encapsulates the 30s timeout, process.kill(), and communicate() behavior so it stays consistent and easier to adjust later.
- On timeout, cover_letter_generator raises RuntimeError while converter returns False, which creates different error semantics for similar failures; it may be worth aligning these behaviors or clearly documenting the difference so callers can handle them consistently.Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
π¨ Severity: CRITICAL
π‘ Vulnerability: Missing
-no-shell-escapeflag inpdflatexand--pdf-engine-opt=-no-shell-escapeinpandocfallback commands insidecli/generators/cover_letter_generator.pyandcli/pdf/converter.pyallowed potential Remote Code Execution (RCE) from untrusted inputs embedded into the.texfiles. Additionally, the lack oftimeoutarguments could cause process hangs (DoS).π― Impact: An attacker or AI hallucination could inject malicious LaTeX commands (like
\immediate\write18{...}) into the generated cover letter or PDF conversion that would be executed by the host system. Furthermore, an infinite loop in the TeX compilation could hang the server indefinitely.π§ Fix: Added
-no-shell-escapeflags and 30-second timeouts with propersubprocess.TimeoutExpiredhandling and process termination.β Verification: Ran
banditandpytest tests/test_pdf_security.pysuccessfully. Checkedpytesttest suite to ensure no breakage.PR created automatically by Jules for task 5092411136245107424 started by @anchapin
Summary by Sourcery
Harden PDF generation against unsafe LaTeX execution and hangs in both cover letter and generic PDF conversion flows.
Bug Fixes:
Enhancements: