grzmol/vibe-force/sf-security-model
Claude Code and agent skill by grzmol/vibe-force
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Salesforce security model and secure-coding enforcement for Apex, LWC, and metadata - org/object/field/record layers, permission sets vs profiles vs permission set groups vs muting permission sets, CRUD and FLS enforcement with WITH USER_MODE, AccessLevel.USER_MODE, Security.stripInaccessible, and Schema describe checks, sharing keywords and Apex managed sharing __Share records, Lightning Web Security and CSP, SOQL injection, XSS, open redirect and CSRF fixes, Named Credentials and protected custom metadata for secrets, Shield Platform Encryption impacts, and Event Monitoring. Use when writing or reviewing @AuraEnabled controllers, triggers, dynamic SOQL, lwc:dom="manual" markup, permission set metadata, integration users, or when running vf-check analyzer or the sf-security-reviewer agent.
Install
npx vskill@latest install grzmol/vibe-force/sf-security-modelSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as grzmol/vibe-force/sf-security-model.
Salesforce Security Model
When to use
- Any Apex class that queries or writes data, especially
@AuraEnabled,@InvocableMethod,@RestResource,global, or Visualforce controller entry points. - Building or reviewing permission metadata (
permissionsets/,permissionsetgroups/, object/field permissions). - Dynamic SOQL/SOSL,
Database.query, string-concatenated queries,lwc:dom="manual",innerHTML, redirects, HTTP callouts with credentials. - Wave 2 of the vibe-force workflow:
sf-security-reviewerreads this skill before reviewing a diff;vf-check analyzerenforces the machine-verifiable subset. - Auditing the standing posture of a whole org rather than one change: skill
sf-org-security-audit, which reuses the permission queries inreferences/permission-architecture.md.
API version 67.0 default-mode change (read this first)
config/vibe-force.defaults.json pins apiVersion 67.0. That version changed the Apex security defaults:
| Behaviour | API 66.0 and earlier | API 67.0 and later | |
|---|---|---|---|
| Database operation access mode | system mode (FLS/object perms ignored) | user mode (FLS, object perms, sharing enforced) | |
| Class with no sharing declaration | resolved per inheritance chain / entry point, often without sharing | `with sharing` | |
| Trigger body DML/SOQL | system mode | user mode, which overrides the trigger's own without sharing context | |
| Anonymous Apex, Connect in Apex | with sharing | with sharing | |
WITH SECURITY_ENFORCED in a SOQL SELECT in Apex | allowed, with limitations | not allowed - the compiler rejects it; use WITH USER_MODE |
Consequences for vibe-force code: never rely on the default. Declare with sharing / inherited sharing / without sharing explicitly on every class with data access, and set an explicit access mode (WITH USER_MODE, WITH SYSTEM_MODE, as user, as system, AccessLevel.*) on every database operation so the code reads the same on any API version. Triggers cannot carry a sharing declaration: they always run without sharing, so delegate to a handler class (see skill sf-apex-development).
Security layer decision table
| Layer | Controls | Configured with | Enforced in Apex by | |
|---|---|---|---|---|
| Org | login IP ranges, hours, MFA, session settings | Setup, security policies | nothing in code | |
| Object (CRUD) | create/read/edit/delete per object | permission sets, permission set groups, profiles | user mode, Schema.DescribeSObjectResult.isCreateable/isAccessible/isUpdateable/isDeletable, stripInaccessible | |
| Field (FLS) | read/edit per field | permission sets (fieldPermissions) | user mode, Schema.DescribeFieldResult, stripInaccessible | |
| Record | which rows a user sees | OWD, role hierarchy, sharing rules, manual shares, Apex managed sharing, restriction rules | class sharing keyword + user mode | |
| Apex/VF class | who may invoke the class | classAccesses / pageAccesses in permission sets | runtime access check on @AuraEnabled and VF entry points | |
| Client | DOM/script isolation | Lightning Web Security, CSP | LWS sandbox, lightning/ui*Api (enforces FLS server-side) |
Object/field permissions and sharing are independent and can coexist; where they conflict, object-level and field-level permissions take precedence over sharing rules.
Core patterns
1. Query in user mode (default choice)
WITH USER_MODE processes every clause including WHERE, supports polymorphic fields (Owner, Task.WhatId), reports all FLS errors, and exposes them through QueryException.getInaccessibleFields(). It is the only clause-based option at our target version: in API 67.0 and later a SOQL SELECT in Apex cannot use WITH SECURITY_ENFORCED at all. Legacy (pre-67.0) code that still carries WITH SECURITY_ENFORCED must be migrated to WITH USER_MODE when its class is raised to 67.0; that clause also reported only the first error, skipped the WHERE clause, ignored polymorphic fields, and was never allowed in AppExchange packages.
2. DML in user mode, with error introspection
Statement form: insert as user expenses; / update as system expenses;. On a user-mode DmlException, getDmlFieldNames() returns the fields that failed FLS.
3. Graceful degradation with stripInaccessible
AccessType values: READABLE, CREATABLE, UPDATABLE, UPSERTABLE. Id is never stripped. AggregateResult is unsupported and throws. Use getModifiedIndexes() to detect that anything was stripped, and sObject.isSet('Field__c') to test a specific field.
4. Dynamic SOQL without injection
Database.queryWithBinds (API 57.0+) resolves binds from a map, so the variables need not be in scope. Bind map keys are compared case-insensitively; duplicate case-variant keys throw QueryException. String.escapeSingleQuotes only helps inside single-quoted literals and is explicitly not the recommended defence. Field and object names cannot be bound: allowlist them (Set<String> of permitted API names) plus a describe accessibility check.
5. Record access beyond sharing rules: Apex managed sharing
Share objects are <Object>Share / MyObject__Share. Access levels: Read, Edit, All (All is managed-sharing only; None applies to AccountShare only). Apex sharing reasons (RowCause) are custom-object-only and survive owner changes; RowCause = 'Manual' shares are deleted when the owner changes. The object's OWD must not already be the most permissive setting, otherwise insert fails with FIELD_FILTER_VALIDATION_EXCEPTION. Details and the recalculation batch pattern: references/sharing-and-record-access.md.
6. Ship permission sets, not profiles
Grant all functional access through permission sets and compose them with permission set groups; use muting permission sets to subtract from a group rather than forking a permission set. Profiles stay minimal (Minimum Access - Salesforce plus license/defaults). Metadata shapes, retrieval caveats, and deployment ordering: references/permission-architecture.md.
7. Secrets never live in source
| Need | Use | Never | |
|---|---|---|---|
| Outbound HTTP auth | Named Credential + External Credential (callout:MyNC/path) | hardcoded tokens, setHeader('Authorization', 'Bearer ...') | |
| Package-scoped secret | protected custom metadata type in a namespaced managed package | custom setting readable by users | |
| Org-local operational secret | protected custom setting / custom metadata restricted by permission set | Apex constant, static resource | |
| Crypto keys/IVs | Crypto.generateAesKey, stored via the above | literal key/IV in Apex (ApexBadCrypto) |
Credentials in ExternalCredential are encrypted by the platform with org-specific keys. vibe-force hooks scan writes for credential-looking literals and block them in standard and strict hook modes; vf-check analyzer flags ApexSuggestUsingNamedCred and ApexBadCrypto.
8. Client-side security
- Lightning Web Security is the default architecture for orgs created in Winter '23 and later and GA for all orgs since Summer '23; it replaces Lightning Locker with per-namespace JavaScript virtualization. Components must not override
window/documentfunctions, must load libraries vialightning/platformResourceLoaderfrom a static resource, and must not use inline<script>. - CSP for Lightning is
default-src 'self',script-src 'self',object-src 'self',style-src 'self' https:,img-src 'self' http: https: data:,connect-src 'self',frame-src https:,frame-ancestors https:,font-src https: data:. Enable the stricter CSP org setting and develop against it.unsafe-inlineandunsafe-evalare not blocked by CSP today but are rejected in AppExchange security review. lightning/uiRecordApi,lightning-record-form, and the other Lightning Data Service wire adapters apply sharing, CRUD, and FLS for you. Prefer them over custom@AuraEnableddata plumbing (skillsf-lwc-development).- Every
@AuraEnabledmethod is a public web service: assume an attacker calls it with arbitrary parameters, regardless of what your component sends.
Anti-patterns
| Anti-pattern | Why it fails | Fix | |
|---|---|---|---|
public class Svc { ... } with DML | sharing mode depends on API version and call chain | declare with sharing (or inherited sharing for reusable services) | |
[SELECT ... FROM Account] in a class saved at 66.0 and callers assuming FLS | pre-67.0 default is system mode | add WITH USER_MODE | |
Database.query('... WHERE Name = \'' + input + '\'') | SOQL injection | Database.queryWithBinds with AccessLevel.USER_MODE | |
String.escapeSingleQuotes(input) on an unquoted boolean/number position | escaping does nothing outside quotes | typecast or allowlist | |
with sharing used as an FLS control | sharing keywords set record access only | add user mode or stripInaccessible | |
stripInaccessible result discarded (insert original;) | inaccessible fields still written | insert decision.getRecords() | |
WITH SECURITY_ENFORCED anywhere in new Apex | rejected by the compiler at API 67.0 and later | WITH USER_MODE | |
this.template.querySelector('div').innerHTML = serverHtml | XSS inside the component | render with template directives, or sanitize before lwc:dom="manual" | |
PageReference(ApexPages.currentPage().getParameters().get('retURL')) | open redirect (ApexOpenRedirect) | allowlist relative paths | |
DML in a constructor or @AuraEnabled(cacheable=true) getter | CSRF-on-GET (ApexCSRF) | move state changes to an explicit POST-style action | |
System.debug(userRecord) with PII, APEX_CODE=FINEST in prod | debug logs leak PII; FINEST logs every variable assignment | scrub logs, cap log level (skill sf-debugging-logs) | |
Integration user with Modify All Data | no least privilege, blast radius on token leak | dedicated integration permission set, object-scoped |
Verification
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/sf-security-model/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/grzmol/vibe-force/sf-security-model)