Skip to content

Commit 0e9f022

Browse files
Fixed bandit Medium severities
Signed-off-by: arpannookala-12 <ganesh.arpan.nookala@cloud2labs.com>
1 parent 3d8041e commit 0e9f022

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

sample_solutions/DocSummarization/backend/api/routes.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import logging
1111
import json
12+
import tempfile
1213

1314
from services import pdf_service, llm_service
1415
import config
@@ -84,14 +85,18 @@ async def summarize_document(
8485

8586
# ========== File Upload (Documents) ==========
8687
if files:
87-
# Save file temporarily
88-
temp_path = f"/tmp/{files.filename}"
88+
# Save file temporarily using secure temp file
8989
filename_lower = files.filename.lower()
9090
logger.info(f"Saving uploaded file: {files.filename}, type={type}")
9191

92-
with open(temp_path, "wb") as buffer:
92+
# Get file extension for temp file
93+
_, file_ext = os.path.splitext(files.filename)
94+
95+
# Create temporary file with proper cleanup
96+
with tempfile.NamedTemporaryFile(delete=False, suffix=file_ext) as temp_file:
9397
content = await files.read()
94-
buffer.write(content)
98+
temp_file.write(content)
99+
temp_path = temp_file.name
95100

96101
try:
97102
# ===== Document Processing (PDF/DOC/DOCX/TXT) =====

sample_solutions/DocSummarization/backend/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def startup_event():
8181
if __name__ == "__main__":
8282
uvicorn.run(
8383
app,
84-
host="0.0.0.0",
84+
host="0.0.0.0", # nosec B104 - Binding to all interfaces is intentional for Docker container
8585
port=config.SERVICE_PORT,
8686
timeout_keep_alive=300
8787
)

0 commit comments

Comments
 (0)