@@ -3,7 +3,6 @@ use std::path::Component;
3
3
use std:: path:: Path ;
4
4
use std:: path:: PathBuf ;
5
5
6
- use AskForApproval :: * ;
7
6
use codex_apply_patch:: ApplyPatchAction ;
8
7
use codex_apply_patch:: ApplyPatchFileChange ;
9
8
@@ -99,18 +98,7 @@ pub fn assess_command_safety(
99
98
// would probably be fine to run the command in a sandbox, but when
100
99
// `approved.contains(command)` is `true`, the user may have approved it for
101
100
// the session _because_ they know it needs to run outside a sandbox.
102
- let command_is_trusted = is_known_safe_command ( command) || approved. contains ( command) ;
103
-
104
- // reject function calls when the model asks for escalated permissions when it should not have to
105
- if let Some ( decision) = reject_forbidden_escalation (
106
- approval_policy,
107
- with_escalated_permissions,
108
- command_is_trusted,
109
- ) {
110
- return decision;
111
- }
112
-
113
- if command_is_trusted {
101
+ if is_known_safe_command ( command) || approved. contains ( command) {
114
102
return SafetyCheck :: AutoApprove {
115
103
sandbox_type : SandboxType :: None ,
116
104
} ;
@@ -127,12 +115,6 @@ pub(crate) fn assess_safety_for_untrusted_command(
127
115
use AskForApproval :: * ;
128
116
use SandboxPolicy :: * ;
129
117
130
- if let Some ( decision) =
131
- reject_forbidden_escalation ( approval_policy, with_escalated_permissions, false )
132
- {
133
- return decision;
134
- }
135
-
136
118
match ( approval_policy, sandbox_policy) {
137
119
( UnlessTrusted , _) => {
138
120
// Even though the user may have opted into DangerFullAccess,
@@ -194,38 +176,6 @@ pub fn get_platform_sandbox() -> Option<SandboxType> {
194
176
}
195
177
}
196
178
197
- /// Forbidden escalation is when the model asks for escalated permissions when it should not have to
198
- /// Rules:
199
- /// The model shouldn't ask for escalated permissions if the command is trusted
200
- /// The model shouldn't ask for escalated permissions if the approval policy is Never
201
- /// The model shouldn't ask for escalated permissions if the approval policy is OnFailure and it hasn't failed
202
- fn reject_forbidden_escalation (
203
- approval_policy : AskForApproval ,
204
- with_escalated_permissions : bool ,
205
- command_is_trusted : bool ,
206
- ) -> Option < SafetyCheck > {
207
- if !with_escalated_permissions {
208
- return None ;
209
- }
210
-
211
- let reason = match approval_policy {
212
- Never => Some (
213
- "auto-rejected. You should not ask for escalated permissions if the approval policy is Never" . to_string ( ) ,
214
- ) ,
215
- OnFailure => Some (
216
- "auto-rejected. You should not ask for escalated permissions if the approval policy is OnFailure and it hasn't failed"
217
- . to_string ( ) ,
218
- ) ,
219
- UnlessTrusted if command_is_trusted => Some (
220
- "auto-rejected. The command is already trusted under the UnlessTrusted approval policy. You do not need to ask for escalated permissions"
221
- . to_string ( ) ,
222
- ) ,
223
- OnRequest | UnlessTrusted => None ,
224
- } ?;
225
-
226
- Some ( SafetyCheck :: Reject { reason } )
227
- }
228
-
229
179
fn is_write_patch_constrained_to_writable_paths (
230
180
action : & ApplyPatchAction ,
231
181
sandbox_policy : & SandboxPolicy ,
@@ -397,62 +347,4 @@ mod tests {
397
347
} ;
398
348
assert_eq ! ( safety_check, expected) ;
399
349
}
400
-
401
- #[ test]
402
- fn test_escalation_rejected_when_policy_is_never ( ) {
403
- let command = vec ! [ "git" . to_string( ) , "status" . to_string( ) ] ;
404
- let approval_policy = AskForApproval :: Never ;
405
- let sandbox_policy = SandboxPolicy :: ReadOnly ;
406
- let approved = HashSet :: new ( ) ;
407
-
408
- let safety_check =
409
- assess_command_safety ( & command, approval_policy, & sandbox_policy, & approved, true ) ;
410
-
411
- assert_eq ! (
412
- safety_check,
413
- SafetyCheck :: Reject {
414
- reason: "auto-rejected. You should not ask for escalated permissions if the approval policy is Never"
415
- . to_string( ) ,
416
- }
417
- ) ;
418
- }
419
-
420
- #[ test]
421
- fn test_escalation_rejected_for_on_failure_policy ( ) {
422
- let command = vec ! [ "git" . to_string( ) , "status" . to_string( ) ] ;
423
- let approval_policy = AskForApproval :: OnFailure ;
424
- let sandbox_policy = SandboxPolicy :: ReadOnly ;
425
- let approved = HashSet :: new ( ) ;
426
-
427
- let safety_check =
428
- assess_command_safety ( & command, approval_policy, & sandbox_policy, & approved, true ) ;
429
-
430
- assert_eq ! (
431
- safety_check,
432
- SafetyCheck :: Reject {
433
- reason:
434
- "auto-rejected. You should not ask for escalated permissions if the approval policy is OnFailure and it hasn't failed"
435
- . to_string( ) ,
436
- }
437
- ) ;
438
- }
439
-
440
- #[ test]
441
- fn test_escalation_rejected_when_trusted_under_unless_trusted ( ) {
442
- let command = vec ! [ "just" . to_string( ) , "fmt" . to_string( ) ] ;
443
- let approval_policy = AskForApproval :: UnlessTrusted ;
444
- let sandbox_policy = SandboxPolicy :: ReadOnly ;
445
- let approved = HashSet :: from ( [ command. clone ( ) ] ) ;
446
-
447
- let safety_check =
448
- assess_command_safety ( & command, approval_policy, & sandbox_policy, & approved, true ) ;
449
-
450
- assert_eq ! (
451
- safety_check,
452
- SafetyCheck :: Reject {
453
- reason: "auto-rejected. The command is already trusted under the UnlessTrusted approval policy. You do not need to ask for escalated permissions"
454
- . to_string( ) ,
455
- }
456
- ) ;
457
- }
458
350
}
0 commit comments