Skip to content

Commit fb4ab0a

Browse files
mazreanclaude
andauthored
Fix: Temporary file cleanup security vulnerability (#67)
* Fix temporary file cleanup security issue This commit addresses a critical security vulnerability where temporary files created during multipart form parsing were not properly cleaned up from disk, potentially leading to: - Information disclosure of sensitive uploaded data - Disk space exhaustion from accumulated temp files - File descriptor leaks in error scenarios Changes: - Added filePath field to preProcessor struct to track temp file location - Modified preProcessor.Close() to explicitly remove temp files using os.Remove() - Ensured both file handle closure and file deletion with proper error handling The existing defer hsc.Close() in Parse() ensures cleanup even on errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * remove filepath field --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 222638d commit fb4ab0a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

parse.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,20 @@ func (pp *preProcessor) Close() error {
219219
return nil
220220
}
221221

222-
return pp.file.Close()
222+
filepath := pp.file.Name()
223+
224+
// Close the file handle first
225+
closeErr := pp.file.Close()
226+
227+
// Remove the temporary file from disk
228+
removeErr := os.Remove(filepath)
229+
230+
// Return combined errors if any
231+
if closeErr != nil || removeErr != nil {
232+
return errors.Join(closeErr, removeErr)
233+
}
234+
235+
return nil
223236
}
224237

225238
type judgeHook struct {

0 commit comments

Comments
 (0)