@@ -1275,21 +1275,9 @@ pub(super) async fn handle_get_sandbox_config(
12751275 crate :: auth:: guard:: enforce_sandbox_scope ( & request, & sandbox_id) ?;
12761276 drop ( request) ;
12771277
1278- let sandbox = state
1279- . store
1280- . get_message :: < Sandbox > ( & sandbox_id)
1281- . await
1282- . map_err ( |e| Status :: internal ( format ! ( "fetch sandbox failed: {e}" ) ) ) ?
1283- . ok_or_else ( || Status :: not_found ( "sandbox not found" ) ) ?;
1278+ let sandbox =
1279+ super :: sandbox:: fetch_and_authorize_sandbox ( state, & principal, & sandbox_id) . await ?;
12841280 let workspace = sandbox. object_workspace ( ) . to_string ( ) ;
1285- authorize_sandbox_workspace (
1286- & state. store ,
1287- & state. admin_role ,
1288- & principal,
1289- & workspace,
1290- MinWorkspaceRole :: User ,
1291- )
1292- . await ?;
12931281 let sandbox_provider_names = sandbox
12941282 . spec
12951283 . as_ref ( )
@@ -2533,20 +2521,8 @@ pub(super) async fn handle_get_sandbox_logs(
25332521 if req. sandbox_id . is_empty ( ) {
25342522 return Err ( Status :: invalid_argument ( "sandbox_id is required" ) ) ;
25352523 }
2536- let sandbox = state
2537- . store
2538- . get_message :: < Sandbox > ( & req. sandbox_id )
2539- . await
2540- . map_err ( |e| Status :: internal ( format ! ( "fetch sandbox failed: {e}" ) ) ) ?
2541- . ok_or_else ( || Status :: not_found ( "sandbox not found" ) ) ?;
2542- authorize_sandbox_workspace (
2543- & state. store ,
2544- & state. admin_role ,
2545- & principal,
2546- sandbox. object_workspace ( ) ,
2547- MinWorkspaceRole :: User ,
2548- )
2549- . await ?;
2524+ let _sandbox =
2525+ super :: sandbox:: fetch_and_authorize_sandbox ( state, & principal, & req. sandbox_id ) . await ?;
25502526
25512527 let lines = if req. lines == 0 { 2000 } else { req. lines } ;
25522528 let tail = state. tracing_log_bus . tail ( & req. sandbox_id , lines as usize ) ;
@@ -13516,6 +13492,69 @@ mod tests {
1351613492 ) ;
1351713493 }
1351813494
13495+ /// ID-based policy handlers must return `NOT_FOUND` — never
13496+ /// `PERMISSION_DENIED` — when the caller lacks workspace access, so that
13497+ /// cross-workspace sandbox existence cannot be inferred (CWE-203).
13498+ #[ tokio:: test]
13499+ async fn id_based_policy_handlers_hide_cross_workspace_sandboxes ( ) {
13500+ let mut state = test_server_state ( ) . await ;
13501+ Arc :: get_mut ( & mut state) . unwrap ( ) . admin_role = "openshell-admin" . to_string ( ) ;
13502+
13503+ fn non_member_request < T > ( inner : T ) -> Request < T > {
13504+ let mut req = Request :: new ( inner) ;
13505+ req. extensions_mut ( ) . insert ( Principal :: User ( UserPrincipal {
13506+ identity : Identity {
13507+ subject : "non-member" . to_string ( ) ,
13508+ display_name : None ,
13509+ roles : vec ! [ ] ,
13510+ scopes : vec ! [ ] ,
13511+ provider : IdentityProvider :: Oidc ,
13512+ } ,
13513+ } ) ) ;
13514+ req
13515+ }
13516+
13517+ let mut sandbox = test_sandbox (
13518+ "sandbox-other" ,
13519+ "other" ,
13520+ ProtoSandboxPolicy :: default ( ) ,
13521+ Vec :: new ( ) ,
13522+ ) ;
13523+ sandbox. metadata . as_mut ( ) . unwrap ( ) . workspace = "other-workspace" . to_string ( ) ;
13524+ state. store . put_message ( & sandbox) . await . unwrap ( ) ;
13525+
13526+ // --- handle_get_sandbox_config ---
13527+ let err = handle_get_sandbox_config (
13528+ & state,
13529+ non_member_request ( GetSandboxConfigRequest {
13530+ sandbox_id : "sandbox-other" . into ( ) ,
13531+ } ) ,
13532+ )
13533+ . await
13534+ . unwrap_err ( ) ;
13535+ assert_eq ! (
13536+ err. code( ) ,
13537+ Code :: NotFound ,
13538+ "handle_get_sandbox_config must return NotFound, not PermissionDenied"
13539+ ) ;
13540+
13541+ // --- handle_get_sandbox_logs ---
13542+ let err = handle_get_sandbox_logs (
13543+ & state,
13544+ non_member_request ( GetSandboxLogsRequest {
13545+ sandbox_id : "sandbox-other" . into ( ) ,
13546+ ..Default :: default ( )
13547+ } ) ,
13548+ )
13549+ . await
13550+ . unwrap_err ( ) ;
13551+ assert_eq ! (
13552+ err. code( ) ,
13553+ Code :: NotFound ,
13554+ "handle_get_sandbox_logs must return NotFound, not PermissionDenied"
13555+ ) ;
13556+ }
13557+
1351913558 #[ tokio:: test]
1352013559 async fn get_gateway_config_accessible_without_platform_admin ( ) {
1352113560 let mut state = test_server_state ( ) . await ;
0 commit comments