@@ -531,7 +531,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
531531 // For read operations in any mode, we skip the coarse-grained block
532532 // and let the request proceed. Fine-grained filtering at Phase 5 will filter
533533 // individual items from the response based on their actual labels from LabelResponse().
534- isReadOperation := ( operation == difc .OperationRead )
534+ isReadOperation := difc .ShouldBypassCoarseDeny ( operation )
535535 result := requestEvaluator .Evaluate (agentLabels .Secrecy , agentLabels .Integrity , resource , operation )
536536
537537 if ! result .IsAllowed () {
@@ -603,8 +603,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
603603 // Per spec: LabelResponse() is only called for read operations in all modes,
604604 // and for read-write operations in filter/propagate modes.
605605 // For write operations and read-write in strict mode, skip LabelResponse().
606- isPureWrite := (operation == difc .OperationWrite )
607- shouldCallLabelResponse := ! isPureWrite && (operation != difc .OperationReadWrite || enforcementMode != difc .EnforcementStrict )
606+ shouldCallLabelResponse := difc .ShouldCallLabelResponse (operation , enforcementMode )
608607
609608 var labeledData difc.LabeledData
610609 if shouldCallLabelResponse {
@@ -631,7 +630,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
631630 filtered .GetAccessibleCount (), filtered .TotalCount )
632631
633632 // **Strict mode: block entire response if ANY item is filtered**
634- if enforcementMode == difc .EnforcementStrict && filtered .GetFilteredCount () > 0 {
633+ if difc .ShouldBlockFilteredResponse ( enforcementMode , filtered .GetFilteredCount ()) {
635634 logger .LogWarn ("difc" , "STRICT MODE: Blocking entire response - %d/%d items violate DIFC policy" ,
636635 filtered .GetFilteredCount (), filtered .TotalCount )
637636 blockErr := fmt .Errorf ("DIFC policy violation: %d of %d items in response are not accessible to agent %s" ,
@@ -664,7 +663,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
664663 // **Phase 6: Accumulate labels from this operation (for reads in PROPAGATE mode only)**
665664 // Label accumulation should only happen when mode is EnforcementPropagate
666665 // Filter mode does NOT accumulate - it just filters what the agent can see
667- if ! isPureWrite && enforcementMode == difc .EnforcementPropagate {
666+ if difc .ShouldAccumulateReadLabels ( operation , enforcementMode ) {
668667 overall := labeledData .Overall ()
669668 agentLabels .AccumulateFromRead (overall )
670669 logUnified .Printf ("[DIFC] Agent %s accumulated labels (propagate mode) | Secrecy: %v | Integrity: %v" ,
@@ -675,7 +674,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
675674 finalResult = backendResult
676675
677676 // **Phase 6: Accumulate labels from resource (for reads in PROPAGATE mode only)**
678- if ! isPureWrite && enforcementMode == difc .EnforcementPropagate {
677+ if difc .ShouldAccumulateReadLabels ( operation , enforcementMode ) {
679678 agentLabels .AccumulateFromRead (resource )
680679 logUnified .Printf ("[DIFC] Agent %s accumulated labels (propagate mode) | Secrecy: %v | Integrity: %v" ,
681680 agentID , agentLabels .GetSecrecyTags (), agentLabels .GetIntegrityTags ())
0 commit comments