sharing-review
Skill1 starsChanged 7 months agoMITView on GitHub
List every Apex class declared `without sharing` or `inherited sharing` and require/verify a justification comment. Catches accidental privilege escalation in service classes.
In this repository53 other files it gives its agents.
- templates/CLAUDE.mdCLAUDE.md
- adrSkill
- agent-deploySkill
- agent-discoverSkill
- agent-eval-trendSkill
- agent-exchange-listSkill
- agent-specSkill
- agent-testSkill
- agent-vs-flow-vs-apexSkill
- before-vs-after-triggerSkill
- code-reviewSkill
- complexitySkill
- coverage-trendSkill
- dead-codeSkill
- dependency-graphSkill
- deploySkill
- destructive-changesSkill
- diff-deploySkill
- erdSkill
- field-impactSkill
- flaky-test-finderSkill
- flow-auditSkill
- flow-vs-apexSkill
- fls-auditSkill
- gateway-configSkill
- generate-docsSkill
- limit-usageSkill
- lwc-vs-reactSkill
- mcp-tool-vs-restSkill
- notifySkill
- onboardSkill
- org-diffSkill
- org-exploreSkill
- package-versionSkill
- pattern-packSkill
- perf-reviewSkill
- permset-auditSkill
- pr-prepareSkill
- queueable-vs-batchSkill
- quick-deploySkill
- react-initSkill
- release-notesSkill
- scratch-orgSkill
- security-scanSkill
- sequence-diagramSkill
- sf-initSkill
- slack-agentSkill
- soql-analyzerSkill
- test-coverageSkill
- test-dataSkill
- test-planSkill
- trust-evalSkill
- trust-layer-auditSkill
The file
Files
You are reviewing sharing keywords on Apex classes. The platform default for new classes should match platform.sharingDefault from config (typically with sharing). Any deviation must be intentional and justified inline.
Read Project Config First
source "${CLAUDE_PLUGIN_ROOT}/hooks/lib/config.sh"
APEX_SRC="$(sf_config_get '.paths.apexSource' "$ENV")"
SHARING_DEFAULT="$(sf_config_get '.platform.sharingDefault' "$ENV")"
TEST_SUFFIX="$(sf_config_get '.naming.apex.testSuffix' "$ENV")"Input
$ARGUMENTS:
- (empty) — review every class
<ClassName>— single class--ci/--format json|sarif/--out <path>
Steps
1. Walk Apex source
For each .cls:
- Capture the class declaration line:
(public|global|private)\s+(virtual\s+)?(?:abstract\s+)?(?:with|without|inherited)\s+sharing\s+class\s+(\w+)(or no sharing keyword at all → defaults towith sharingfor top-level classes; see Apex docs) - Skip test classes unless
--include-tests
2. Classify
| Pattern | Verdict | Rule ID |
with sharing and matches SHARING_DEFAULT | ✅ ok | — |
| (no sharing keyword) | ✅ ok (defaults to with sharing) but suggest making explicit | SHR-IMPLICIT-SHARING (note) |
inherited sharing | ✅ ok if used as utility called from with sharing callers | SHR-INHERITED-SHARING (note) |
without sharing and no justification comment within 5 lines above | ⚠️ warning | SHR-WITHOUT-SHARING-NO-JUSTIFICATION |
without sharing with justification comment | ✅ acknowledged | SHR-WITHOUT-SHARING (note) |
A "justification comment" is a line within 5 lines above the class declaration matching:
//\s*(?:reason|why|justification):\s*\S+3. Cross-check usage
For every without sharing class, find callers via grep:
grep -lE "\b<ClassName>\." "${APEX_SRC}"/*.cls "${APEX_SRC}"/*.triggerFlag a without sharing class only called from with sharing callers — that's safe. Flag with elevated severity any without sharing class called from @AuraEnabled methods (those run as the user; the privilege escalation is the bug).
4. Output
Default Markdown:
# Sharing Review: <project.name>
Sharing default: with sharing
Classes scanned: 47 production
Run at: 2026-04-28T13:15:00Z
## Findings
### Critical (without sharing called from @AuraEnabled) — 1
- `force-app/.../AdminUtils.cls` (`without sharing`) is called from
`OrderController.createOrder` (@AuraEnabled). This bypasses the user's
sharing rules at LWC entry. Add an explicit access check or move the
privileged code behind a server-only entry point. (SHR-WITHOUT-SHARING-AURA-ESCAPE)
### Warning (without sharing without justification) — 2
- `force-app/.../LegacyJob.cls` — declare a justification comment:
// reason: scheduled job runs as system; needs cross-org visibility
- `force-app/.../OldHelper.cls` — same
### Note (without sharing with justification) — 3
- `force-app/.../IntegrationUser.cls` // reason: integration user has restricted profile; sharing not applicable
- ...
### Note (implicit `with sharing`) — 12
- (consider adding the explicit keyword for clarity)CI mode: emit findings via SARIF.
5. Exit codes
- 0 — no findings (or only
noteseverity) - 1 — any warning or error
- 2 — config error
Rules
- Justification comments must be specific. "// reason: legacy" is not enough. Look for either a referenced ticket / ADR or a domain-specific reason
- AuraEnabled escape is the worst case. A
without sharingclass touched by an@AuraEnabledmethod bypasses the user's sharing rules — that's almost always wrong. Treat aserror inherited sharingis fine for utilities. It defers to the calling class and matches the principle of least surprise- Don't include test classes unless
--include-tests - Don't auto-rewrite. Sharing changes are operational decisions; the user makes them
Consumers
@security-reviewerreads this skill's findings as part of its review/argo:code-reviewcross-links to this skill when it sees a class touch DML- ADRs may justify a
without sharingchoice —/adrlinkable from the justification comment
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

