Skip to main content

AGENTFORCE-APEX-05: Async Apex Job Drops the Caller's Sharing Context

๐Ÿ”ด High ยท Broken Access Control

Detects Queueable, Finalizer, Batchable and Schedulable classes declared without sharing, or with no sharing keyword (an async entry point with no keyword runs without sharing), that query or write records without user mode, and that are started (System.enqueueJob, System.attachFinalizer, Database.executeBatch, System.schedule) from a class declared with or inherited sharing, or from Apex that users or agents can call, with constructor arguments that carry the caller's data into the job. The job runs in system context, so records the caller cannot see are read or changed in its name. Severity: high when the starting class is externally callable or agent-targeted and the job is a Queueable or Finalizer, medium otherwise; Batchable and Schedulable jobs are reported only when users or agents can start them.

Detailsโ€‹

FieldValue
Rule IDAGENTFORCE-APEX-05
SeverityHigh
CategoryBroken Access Control
ComplianceSOC2_CC6, HIPAA

Remediationโ€‹

Declare the job 'with sharing' or 'inherited sharing' (an entry point declared inherited sharing runs with sharing), run its queries and DML in AccessLevel.USER_MODE / 'as user', or re-check the caller's record access before the work is queued.

See Alsoโ€‹