1111from libs .models .entities import Process
1212from libs .repositories .process_repository import ProcessRepository
1313from libs .services .auth import get_authenticated_user
14+ from libs .services .authorization import verify_process_ownership
1415from libs .services .interfaces import ILoggerService
1516from libs .services .process_services import ProcessService
1617from routers .models .files import FileInfo
@@ -83,6 +84,11 @@ async def status(process_id: str, request: Request):
8384 f"Process router status endpoint called for process_id: { process_id } "
8485 )
8586
87+ # Authenticate the caller and verify they own this process
88+ authenticated_user = get_authenticated_user (request )
89+ user_id = authenticated_user .user_principal_id
90+ await verify_process_ownership (app , process_id , user_id )
91+
8692 # loading business component for process
8793 processService = app .app_context .get_service (ProcessService )
8894
@@ -99,6 +105,11 @@ async def render_status(process_id: str, request: Request):
99105 f"Process router render status endpoint called for process_id: { process_id } "
100106 )
101107
108+ # Authenticate the caller and verify they own this process
109+ authenticated_user = get_authenticated_user (request )
110+ user_id = authenticated_user .user_principal_id
111+ await verify_process_ownership (app , process_id , user_id )
112+
102113 # loading business component for process
103114 processService = app .app_context .get_service (ProcessService )
104115
@@ -138,6 +149,9 @@ async def upload_files(
138149 if not user_id :
139150 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
140151
152+ # Verify the caller owns this process before touching its blob storage
153+ await verify_process_ownership (app , process_id , user_id )
154+
141155 # Make uploaded files list
142156 uploaded_files : list [FileInfo ] = []
143157
@@ -195,6 +209,8 @@ async def upload_files(
195209 response .headers ["Location" ] = f"/process/{ process_id } /"
196210
197211 return result_response
212+ except HTTPException :
213+ raise
198214 except Exception as e :
199215 logger_service .log_error (f"Error in upload_files: { str (e )} " )
200216 raise HTTPException (status_code = 500 , detail = f"Error uploading files: { str (e )} " )
@@ -233,6 +249,9 @@ async def delete_file(
233249 if not user_id :
234250 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
235251
252+ # Verify the caller owns this process before deleting any file
253+ await verify_process_ownership (app , process_id , user_id )
254+
236255 # Get process service
237256 processService = app .app_context .get_service (ProcessService )
238257
@@ -274,6 +293,8 @@ async def delete_file(
274293 status_code = 404 ,
275294 detail = f"File '{ file_name } ' not found for process '{ process_id } '" ,
276295 )
296+ except HTTPException :
297+ raise
277298 except Exception as e :
278299 logger_service .log_error (f"Error in delete_file: { str (e )} " )
279300 raise HTTPException (status_code = 500 , detail = f"Error deleting file: { str (e )} " )
@@ -309,6 +330,9 @@ async def delete_process(
309330 if not user_id :
310331 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
311332
333+ # Verify the caller owns this process before deleting its files
334+ await verify_process_ownership (app , process_id , user_id )
335+
312336 # Get process service
313337 processService = app .app_context .get_service (ProcessService )
314338
@@ -333,6 +357,8 @@ async def delete_process(
333357
334358 return result_response
335359
360+ except HTTPException :
361+ raise
336362 except Exception as e :
337363 logger_service .log_error (f"Error in delete_process: { str (e )} " )
338364 raise HTTPException (status_code = 500 , detail = f"Error deleting process: { str (e )} " )
@@ -365,6 +391,9 @@ async def start_processing(
365391 if not user_id :
366392 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
367393
394+ # Verify the caller owns this process before queueing it for processing
395+ await verify_process_ownership (app , process_id , user_id )
396+
368397 # Get process service
369398 processService = app .app_context .get_service (ProcessService )
370399
@@ -394,6 +423,8 @@ async def start_processing(
394423 "user_id" : str (user_id ),
395424 "status" : "queued" ,
396425 }
426+ except HTTPException :
427+ raise
397428 except Exception as e :
398429 logger_service .log_error (f"Error in start_processing: { str (e )} " )
399430 raise HTTPException (
@@ -425,6 +456,9 @@ async def download_process_files(
425456 if not user_id :
426457 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
427458
459+ # Verify the caller owns this process before returning its files
460+ await verify_process_ownership (app , process_id , user_id )
461+
428462 # Get process service
429463 processService = app .app_context .get_service (ProcessService )
430464
@@ -492,6 +526,9 @@ async def get_process_summary(
492526 if not user_id :
493527 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
494528
529+ # Verify the caller owns this process before returning its summary
530+ await verify_process_ownership (app , process_id , user_id )
531+
495532 # Get process service
496533 processService = app .app_context .get_service (ProcessService )
497534
@@ -549,6 +586,9 @@ async def get_file_content(
549586 if not user_id :
550587 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
551588
589+ # Verify the caller owns this process before returning file content
590+ await verify_process_ownership (app , process_id , user_id )
591+
552592 # Get process service
553593 processService = app .app_context .get_service (ProcessService )
554594
@@ -607,6 +647,9 @@ async def cancel_process(
607647 if not user_id :
608648 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
609649
650+ # Verify the caller owns this process before forwarding the kill request
651+ await verify_process_ownership (app , process_id , user_id )
652+
610653 # Get processor control URL from configuration
611654 config = app .app_context .configuration
612655 processor_url = config .processor_control_url or "http://processor:8080"
@@ -704,6 +747,9 @@ async def get_cancel_status(
704747 if not user_id :
705748 raise HTTPException (status_code = 401 , detail = "User not authenticated" )
706749
750+ # Verify the caller owns this process before reading its cancel status
751+ await verify_process_ownership (app , process_id , user_id )
752+
707753 # Get processor control URL from configuration
708754 config = app .app_context .configuration
709755 processor_url = config .processor_control_url or "http://processor:8080"
0 commit comments