π‘οΈ Sentinel: [CRITICAL] Fix RCE and DoS vulnerabilities in PDF compilation#384
π‘οΈ Sentinel: [CRITICAL] Fix RCE and DoS vulnerabilities in PDF compilation#384anchapin wants to merge 2 commits into
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 GuideThis PR hardens PDF compilation against RCE and DoS by disabling LaTeX shell escapes and enforcing 30s timeouts with cleanup on all pdflatex/pandoc subprocess calls, and adds tests to validate the new behavior. Sequence diagram for secured PDF compilation with pdflatex and pandocsequenceDiagram
participant CoverLetterGenerator
participant subprocess
participant pdflatex_process
participant pandoc_process
CoverLetterGenerator->>subprocess: Popen(pdflatex, -interaction=nonstopmode, -no-shell-escape)
subprocess-->>CoverLetterGenerator: pdflatex_process
CoverLetterGenerator->>pdflatex_process: communicate(timeout=30)
alt [TimeoutExpired]
CoverLetterGenerator->>pdflatex_process: kill()
CoverLetterGenerator->>pdflatex_process: communicate()
CoverLetterGenerator-->>CoverLetterGenerator: pdf_created = False
else [pdflatex returns success or output_path exists]
pdflatex_process-->>CoverLetterGenerator: returncode, stdout, stderr
CoverLetterGenerator-->>CoverLetterGenerator: pdf_created = True
else [pdflatex fails]
CoverLetterGenerator->>subprocess: Popen(pandoc, --pdf-engine=xelatex, --pdf-engine-opt=-no-shell-escape)
subprocess-->>CoverLetterGenerator: pandoc_process
CoverLetterGenerator->>pandoc_process: communicate(timeout=30)
alt [TimeoutExpired]
CoverLetterGenerator->>pandoc_process: kill()
CoverLetterGenerator->>pandoc_process: communicate()
CoverLetterGenerator-->>CoverLetterGenerator: pdf_created = False
else [pandoc returns success or output_path exists]
pandoc_process-->>CoverLetterGenerator: returncode, stdout, stderr
CoverLetterGenerator-->>CoverLetterGenerator: pdf_created = True
end
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 found 1 issue, and left some high level feedback:
- The 30-second timeout and kill/cleanup logic for pdflatex/pandoc is duplicated across PDFConverter and CoverLetterGenerator; consider extracting a shared helper to centralize and standardize this security-sensitive subprocess handling.
- The hard-coded 30-second timeout value is repeated in several places; defining a single configuration or module-level constant for the PDF compilation timeout would make future tuning easier and reduce the chance of inconsistent behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The 30-second timeout and kill/cleanup logic for pdflatex/pandoc is duplicated across PDFConverter and CoverLetterGenerator; consider extracting a shared helper to centralize and standardize this security-sensitive subprocess handling.
- The hard-coded 30-second timeout value is repeated in several places; defining a single configuration or module-level constant for the PDF compilation timeout would make future tuning easier and reduce the chance of inconsistent behavior.
## Individual Comments
### Comment 1
<location path="cli/pdf/converter.py" line_range="101" />
<code_context>
+
if process.returncode == 0 or output_path.exists():
pdf_created = True
except (subprocess.CalledProcessError, FileNotFoundError):
</code_context>
<issue_to_address>
**suggestion:** Remove `CalledProcessError` from this exception list when using `Popen`.
`subprocess.Popen` with `communicate()` does not raise `CalledProcessError`, so including it here implies an impossible failure mode. Removing it will make the actual error handling path more accurate and easier to understand.
</issue_to_address>Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
| except subprocess.TimeoutExpired: | ||
| process.kill() | ||
| process.communicate() | ||
| return False |
There was a problem hiding this comment.
suggestion: Remove CalledProcessError from this exception list when using Popen.
subprocess.Popen with communicate() does not raise CalledProcessError, so including it here implies an impossible failure mode. Removing it will make the actual error handling path more accurate and easier to understand.
Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
-no-shell-escapeflags topdflatexandpandoccalls, and added 30-second timeouts with cleanuptest_pdf_security.pyPR created automatically by Jules for task 9649511856481661638 started by @anchapin
Summary by Sourcery
Harden PDF compilation against RCE and DoS by constraining LaTeX and pandoc subprocess execution.
Bug Fixes:
Enhancements:
Documentation:
Tests: