Skip to content

Commit 64e8ae1

Browse files
CopilotMte90
andcommitted
Fix security issue: prevent stack trace exposure in error responses
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent d24bad4 commit 64e8ae1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,15 @@ def api_query(http_request: Request, request: QueryRequest):
270270
return JSONResponse(result)
271271
except ValueError as e:
272272
# ValueError for not found or not indexed
273+
# Log the full error but return generic message
273274
logger.warning(f"Query validation failed: {e}")
274-
return JSONResponse({"error": str(e)}, status_code=400)
275+
# Return safe, generic error messages
276+
if "not found" in str(e).lower():
277+
return JSONResponse({"error": "Project not found"}, status_code=404)
278+
elif "not indexed" in str(e).lower():
279+
return JSONResponse({"error": "Project not indexed yet"}, status_code=400)
280+
else:
281+
return JSONResponse({"error": "Invalid request"}, status_code=400)
275282
except Exception as e:
276283
logger.exception(f"Error querying project: {e}")
277284
return JSONResponse({"error": "Query failed"}, status_code=500)

0 commit comments

Comments
 (0)