Skip to content

Security: mirrexa/salesforce-app

Security

SECURITY.md

Mirrexa Salesforce App - Security Documentation

Overview

This document outlines the comprehensive security controls implemented in the Mirrexa Salesforce application to ensure compliance with Salesforce AppExchange security review requirements and enterprise security standards.

Security Architecture

1. Object-Level Security (CRUD)

All Apex classes implement proper Create, Read, Update, Delete (CRUD) permission checks before performing any data operations.

Implementation Pattern:

// Check object accessibility before SOQL queries
if (!Schema.sObjectType.PermissionSetAssignment.isAccessible()) {
    throw new AuraHandledException('Insufficient permissions to access Permission Set Assignments');
}

// Check object permissions before DML operations
if (!Schema.sObjectType.PermissionSetAssignment.isCreateable()) {
    throw new AuraHandledException('Insufficient permissions to create Permission Set Assignments');
}

Applied to:

  • MirrexaAdminController.cls - All SOQL queries and DML operations
  • MirrexaApiService.cls - User and Organization object access
  • All permission set assignment operations

2. Field-Level Security (FLS)

All field access is validated before reading or writing field data to ensure users can only access fields they have permission to view.

Implementation Pattern:

// Check field-level security before accessing fields
if (!Schema.sObjectType.User.fields.Username.isAccessible() ||
    !Schema.sObjectType.User.fields.Email.isAccessible()) {
    throw new AuraHandledException('Insufficient field permissions for User records');
}

Applied to:

  • User fields: Id, Username, Email, Name, IsActive
  • PermissionSetAssignment fields: Id, AssigneeId, SystemModstamp
  • PermissionSet fields: Id, Name, Label, Description, Type
  • NamedCredential fields: Id, DeveloperName
  • Organization fields: InstanceName

3. Sharing and Access Control

Apex Sharing Model

All Apex classes use with sharing to enforce record-level security:

public with sharing class MirrexaAdminController {
    // Class respects user's sharing rules and record access
}

public with sharing class MirrexaApiService {
    // Class respects user's sharing rules and record access
}

Permission Set Security

The Mirrexa_App_Access_2GP permission set follows the principle of least privilege:

<objectPermissions>
    <allowCreate>false</allowCreate>     <!-- No create permissions -->
    <allowDelete>false</allowDelete>     <!-- No delete permissions -->
    <allowEdit>false</allowEdit>         <!-- No edit permissions -->
    <allowRead>true</allowRead>          <!-- Read-only access -->
    <modifyAllRecords>false</modifyAllRecords>
    <viewAllRecords>false</viewAllRecords> <!-- No view all access -->
    <object>UserExternalCredential</object>
</objectPermissions>

4. Input Validation and Sanitization

SOQL Injection Prevention

All user inputs are sanitized to prevent SOQL injection attacks:

// Sanitize input to prevent SOQL injection
String sanitizedSearchTerm = String.escapeSingleQuotes(searchTerm.trim());
if (sanitizedSearchTerm.length() > 255) {
    throw new AuraHandledException('Search term too long');
}

Input Format Validation

Strict validation patterns for all user inputs:

// Salesforce ID format validation
if (!Pattern.matches('[a-zA-Z0-9]{15}|[a-zA-Z0-9]{18}', userId)) {
    throw new AuraHandledException('Invalid User ID format: ' + userId);
}

// Template ID format validation
if (!Pattern.matches('[a-zA-Z0-9_-]{1,50}', templateId)) {
    throw new AuraHandledException('Invalid template ID format');
}

Bulk Operation Limits

Protection against resource exhaustion:

// Limit bulk operations to prevent resource abuse
if (userIds.size() > 200) {
    throw new AuraHandledException('Cannot process more than 200 users at once');
}

5. External API Security

HTTP Request Security

All external API calls implement security best practices:

HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Mirrexa_API/api/user');
req.setMethod('GET');
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
req.setTimeout(30000); // 30-second timeout to prevent hanging requests

Response Validation

All API responses are validated before processing:

if (res.getStatusCode() >= 200 && res.getStatusCode() < 300) {
    String responseBody = res.getBody();
    
    // Validate response is not empty
    if (String.isBlank(responseBody)) {
        throw new AuraHandledException('Empty response from Mirrexa API');
    }
    
    // Validate JSON format to prevent malformed data processing
    try {
        Object parsedResponse = JSON.deserializeUntyped(responseBody);
        return responseBody;
    } catch (JSONException e) {
        System.debug('Invalid JSON response from Mirrexa API: ' + responseBody);
        throw new AuraHandledException('Invalid response format from Mirrexa API');
    }
}

Named Credentials

Secure authentication using Salesforce Named Credentials:

  • OAuth 2.0 flow for user authentication
  • Encrypted credential storage
  • Per-user principal access control

6. Error Handling and Security

Security Exception Preservation

Error handling preserves security exceptions while gracefully handling unexpected errors:

try {
    // Business logic with security checks
} catch (AuraHandledException e) {
    // Re-throw validation and security exceptions
    throw e;
} catch (Exception e) {
    // Log unexpected errors without exposing sensitive information
    System.debug('Error in operation: ' + e.getMessage());
    result.put('error', 'An unexpected error occurred');
}

Secure Error Messages

  • Security violations return appropriate error messages
  • Sensitive information is never exposed in error messages
  • Debug logs contain detailed information for troubleshooting

7. Data Privacy and Compliance

PII Handling

  • No personally identifiable information is stored locally
  • All user data is accessed through Salesforce's secure APIs
  • External API calls use encrypted HTTPS connections

Data Retention

  • No persistent data storage outside of Salesforce
  • Temporary data is processed in memory only
  • External API responses are not cached

Security Testing

Test Coverage

Comprehensive security test suite validates all security controls:

  • MirrexaSecurityValidationTest.cls - Core security pattern validation
  • MirrexaSecurityTest.cls - Integration security testing
  • SOQL injection prevention testing
  • Input validation testing
  • Bulk operation limit testing
  • Exception handling testing

Test Execution

# Run security validation tests
sfdx force:apex:test:run --tests MirrexaSecurityValidationTest --result-format human

# Run comprehensive security tests
sfdx force:apex:test:run --tests MirrexaSecurityTest --result-format human

Security Configuration

Remote Site Settings

External API access is restricted to necessary endpoints:

  • https://api.mirrexa.ai - Mirrexa API endpoint (HTTPS only)

Connected App Configuration

  • Minimal OAuth scopes
  • Per-user authentication
  • Secure token handling

Permission Set Assignment

  • Manual assignment required
  • No automatic permission escalation
  • Regular access review recommended

Security Monitoring

Logging

  • Security exceptions are logged for monitoring
  • Failed authentication attempts are tracked
  • Unusual API usage patterns are logged

Audit Trail

  • All permission set assignments are tracked
  • User access changes are logged
  • API usage is monitored through Salesforce logs

Compliance Standards

This implementation meets the following security standards:

Salesforce AppExchange Security Review RequirementsOWASP Top 10 Web Application Security RisksPrinciple of Least PrivilegeDefense in DepthSecure by Design

Security Review Checklist

  • CRUD/FLS checks implemented on all data operations
  • Input validation and SOQL injection prevention
  • Proper sharing model (with sharing)
  • Least privilege permission sets
  • Secure external API handling
  • Comprehensive error handling
  • Security test coverage
  • Documentation and code comments
  • No hardcoded secrets or credentials
  • HTTPS-only external communications

Maintenance and Updates

Security Updates

  • Regular review of permission sets and access controls
  • Monitoring of Salesforce security advisories
  • Updates to input validation patterns as needed

Code Reviews

  • All security-related code changes require review
  • Security patterns must be maintained in new features
  • Regular security audits recommended

Document Version: 1.0
Last Updated: 2025-08-13
Next Review: 2025-11-13

There aren’t any published security advisories