apex-security-hardening

Harden Apex controllers with USER_MODE CRUD/FLS enforcement and least-privilege permission sets.

Updated Sep 23, 2026
One-click install
npx skills add https://github.com/drgaciw/rlm-base-dev-fork --skill apex-security-hardening-drgaciw
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: apex-security-hardening
Source: https://github.com/drgaciw/rlm-base-dev-fork/tree/main/.cursor/skills/apex-security-hardening
Command: npx skills add https://github.com/drgaciw/rlm-base-dev-fork --skill apex-security-hardening-drgaciw

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Apex controllers often run SOQL and DML in system mode, bypassing the caller's CRUD and field-level security, while permission sets are built by guesswork and end up over-granted or silently incomplete after deployment. This Skill provides a canonical workflow to enforce user-mode security and prove the backing permission set grants exactly what the code needs. ## Core Features & Use Cases - USER_MODE Conversion: Detect every system-mode static query in controllers and convert SOQL to WITH USER_MODE and DML to as user with correct clause placement. - Least-Privilege Permission Sets: Derive object CRUD and field FLS grants directly from the user-mode code surface, cross-checked against field permissionability via sf sobject describe. - Deploy Verification: Read the permission set back from the org with SOQL queries to catch silent drops from master-detail children and compound-address fields, then prove sufficiency with persona walks or System.runAs tests. - Use Case: Before a Salesforce security audit, run the hardening pass on an @AuraEnabled quoting controller, build its permission set from the enumerated fields, deploy it, and confirm org read-back matches the file. ## Quick Start Review my Apex controller for system-mode SOQL and DML, convert it to USER_MODE, and generate the least-privilege permission set it requires.

Frequently Asked Questions about apex-security-hardening

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce CRUD and FLS in Apex SOQL queries?▼

Add WITH USER_MODE to every static SOQL query and dynamic query string reachable from @AuraEnabled, @InvocableMethod, VF, or webservice entry points. Place the clause after WHERE (or after FROM when there is no WHERE) and before GROUP BY, ORDER BY, or LIMIT.

How do I build a least-privilege Salesforce permission set from Apex code?▼

Enumerate every object and field touched by user-mode queries and DML, then grant object CRUD plus fieldPermissions only for permissionable fields. Use sf sobject describe to check the permissionable flag, and set editable=true only on fields the code writes.

Why does my permission set deploy succeed but object permissions are missing?▼

Master-detail child objects have CRUD controlled by the master, and the platform silently drops child object permissions on deploy. Grant the master object instead, such as Quote read/edit covering QuoteLineItem, and verify with an org read-back query.

Why do I get 'Invalid field permission field name' for address fields?▼

Standard compound-address components like BillingStreet and ShippingCountry report permissionable=true but reject permission-set fieldPermissions. Drop those FLS rows because object-level read access already covers them.

Do passing Apex tests prove my permission set is sufficient?▼

No. Tests run as admin and bypass FLS, so a green suite does not exercise the permission set. Confirm sufficiency with a System.runAs test or a persona walk using a non-admin user assigned only the permission set.