-
Notifications
You must be signed in to change notification settings - Fork 139
Fix Memory Exhaustion and DoS for PDF uploads (#1549) #1550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b1bb2d8
9ca5b8a
dc3ea2d
2759ba2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| const axios = require("axios"); | ||
| const crypto = require("crypto"); | ||
| const fs = require("fs"); | ||
| const { generateWithFallback } = require("../utils/geminiHelper"); | ||
| const { | ||
| inspectPdfBuffer, | ||
|
|
@@ -103,14 +104,16 @@ | |
| * @example | ||
| */ | ||
| const summarizeNotes = async (req, res) => { | ||
| let uploadedFilePath = null; | ||
| try { | ||
| let buffer; | ||
| let fileName; | ||
| let sourceType; | ||
| let sourceUrl = null; | ||
|
|
||
| if (req.file) { | ||
| buffer = req.file.buffer; | ||
| uploadedFilePath = req.file.path; | ||
| buffer = await fs.promises.readFile(uploadedFilePath); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| fileName = req.file.originalname; | ||
| sourceType = "upload"; | ||
| } else { | ||
|
|
@@ -238,6 +241,10 @@ | |
| } | ||
|
|
||
| res.status(500).json({ success: false, message: "Failed to summarize notes." }); | ||
| } finally { | ||
| if (uploadedFilePath) { | ||
| fs.promises.unlink(uploadedFilePath).catch(err => console.error("Failed to delete temp notes PDF:", err)); | ||
| } | ||
|
Comment on lines
+247
to
+252
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π©Ί Stability & Availability | π Major | ποΈ Heavy lift Make temporary-file cleanup cover the complete post-upload lifecycle. The controller
π Affects 2 files
π€ Prompt for AI Agents |
||
| } | ||
| }; | ||
|
|
||
|
|
@@ -257,7 +264,7 @@ | |
| message: validation.error.issues.map((issue) => issue.message), | ||
| }); | ||
| } | ||
|
|
||
Check failureCode scanning / CodeQL Uncontrolled data used in path expression High
This path depends on a
user-provided value Error loading related location Loading |
||
| const { | ||
| fileName, | ||
| sourceType, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.