2025-09-02 16:09:17 +09:00
# Salesforce-to-Portal Security Integration Guide
2025-09-06 10:01:44 +09:00
Note: 2025 update — Salesforce → Portal order provisioning is now event-driven via Platform Events. This document reflects the event-driven model.
2025-09-02 16:09:17 +09:00
## Overview
This guide outlines secure patterns for **Salesforce-to-Portal communication** specifically for the **order provisioning workflow** . Based on your architecture, this focuses on order status updates, not invoice handling.
2025-09-06 10:01:44 +09:00
## Order Provisioning Flow (Async Preferred)
2025-09-02 16:09:17 +09:00
```
Portal Customer → Places Order → Salesforce Order (Pending Review)
↓
2025-09-06 10:01:44 +09:00
Salesforce Operator → Reviews/Approves Order
2025-09-02 16:09:17 +09:00
↓
2025-09-06 10:01:44 +09:00
Salesforce Flow → Publishes OrderProvisionRequested__e
2025-09-02 16:09:17 +09:00
↓
2025-09-06 10:01:44 +09:00
Portal BFF Subscriber → Provisions in WHMCS → Updates Salesforce Order Status
2025-09-02 16:09:17 +09:00
↓
2025-09-06 10:01:44 +09:00
Portal → Polls Order Status → Shows Customer Updates
2025-09-02 16:09:17 +09:00
```
## 1. Secure Order Provisioning Communication
2025-09-06 10:01:44 +09:00
### Primary Method: Platform Events (Recommended)
2025-09-02 16:09:17 +09:00
2025-09-06 10:01:44 +09:00
Use a Record-Triggered Flow to publish `OrderProvisionRequested__e` . The portal subscribes via the Salesforce Streaming API (Pub/Sub) and provisions asynchronously. Inbound webhooks from Salesforce are no longer required.
2025-09-02 16:09:17 +09:00
2025-09-06 10:01:44 +09:00
If you still need synchronous HTTP for another use case, prefer OAuth2 Named/External Credential and avoid custom signature schemes.
2025-09-02 16:09:17 +09:00
2025-09-06 10:01:44 +09:00
### Secure Salesforce Quick Action Setup (Legacy)
2025-09-02 16:09:17 +09:00
2025-09-06 10:01:44 +09:00
Legacy Quick Action + webhook details removed (use Platform Events).
2025-09-02 16:09:17 +09:00
2. **Apex Class for Secure Webhook Calls**
2025-09-09 18:19:54 +09:00
// Your current pattern in salesforce-connection.service.ts
// Uses private key JWT authentication - industry standard
````
2025-09-02 16:09:17 +09:00
### Enhanced Patterns for Sensitive Operations
For highly sensitive operations, consider adding:
```typescript
@Injectable ()
export class SecureSalesforceService {
async createSensitiveRecord(data: SensitiveData, idempotencyKey: string) {
// 1. Encrypt sensitive fields before sending
const encryptedData = this.encryptSensitiveFields(data);
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
// 2. Add idempotency protection
const headers = {
'Idempotency-Key': idempotencyKey,
'X-Request-ID': uuidv4(),
};
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
// 3. Use your existing secure connection
return await this.salesforceConnection.create(encryptedData, headers);
}
private encryptSensitiveFields(data: any): any {
// Encrypt PII fields before transmission
const sensitiveFields = ['ssn', 'creditCard', 'personalId'];
// Implementation depends on your encryption strategy
}
}
2025-09-09 18:19:54 +09:00
````
2025-09-02 16:09:17 +09:00
## 3. Data Protection Guidelines
### Sensitive Data Handling
```typescript
// Example: Secure order processing
export class SecureOrderService {
async processOrderApproval(orderData: OrderApprovalData) {
// 1. Validate customer permissions
await this.validateCustomerAccess(orderData.customerNumber);
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
// 2. Sanitize data for logging
const sanitizedData = this.sanitizeForLogging(orderData);
2025-09-09 18:19:54 +09:00
this.logger.log("Processing order approval", sanitizedData);
2025-09-02 16:09:17 +09:00
// 3. Process with minimal data exposure
const result = await this.processOrder(orderData);
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
// 4. Audit trail without sensitive data
await this.createAuditLog({
2025-09-09 18:19:54 +09:00
action: "order_approved",
2025-09-02 16:09:17 +09:00
customerNumber: orderData.customerNumber,
orderId: orderData.orderId,
timestamp: new Date(),
// No sensitive payment or personal data
});
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
return result;
}
private sanitizeForLogging(data: any): any {
// Remove or mask sensitive fields for logging
const { creditCard, ssn, ...safeData } = data;
return {
...safeData,
2025-09-09 18:19:54 +09:00
creditCard: creditCard ? "****" + creditCard.slice(-4) : undefined,
ssn: ssn ? "***-**-" + ssn.slice(-4) : undefined,
2025-09-02 16:09:17 +09:00
};
}
}
```
### Field-Level Security
```typescript
// Implement field-level encryption for highly sensitive data
export class FieldEncryptionService {
2025-09-09 18:19:54 +09:00
private readonly algorithm = "aes-256-gcm";
private readonly keyDerivation = "pbkdf2";
2025-09-02 16:09:17 +09:00
async encryptField(value: string, fieldType: string): Promise< EncryptedField > {
const key = await this.deriveKey(fieldType);
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipher(this.algorithm, key);
2025-09-09 18:19:54 +09:00
let encrypted = cipher.update(value, "utf8", "hex");
encrypted += cipher.final("hex");
2025-09-02 16:09:17 +09:00
return {
value: encrypted,
2025-09-09 18:19:54 +09:00
iv: iv.toString("hex"),
tag: cipher.getAuthTag().toString("hex"),
2025-09-02 16:09:17 +09:00
};
}
async decryptField(encryptedField: EncryptedField, fieldType: string): Promise< string > {
const key = await this.deriveKey(fieldType);
const decipher = crypto.createDecipher(this.algorithm, key);
2025-09-09 18:19:54 +09:00
decipher.setAuthTag(Buffer.from(encryptedField.tag, "hex"));
let decrypted = decipher.update(encryptedField.value, "hex", "utf8");
decrypted += decipher.final("utf8");
2025-09-02 16:09:17 +09:00
return decrypted;
}
}
```
## 4. Implementation Checklist
### Salesforce Setup
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
- [ ] Create Platform Events for portal notifications
- [ ] Configure IP allowlisting for portal endpoints
- [ ] Create audit trails for all portal communications
### Portal Setup
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
- [ ] Add IP allowlisting for Salesforce
- [ ] Create encrypted payload handling
- [ ] Implement idempotency protection
### Security Measures
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
- [ ] Implement rate limiting per customer
- [ ] Add comprehensive audit logging
- [ ] Test disaster recovery procedures
## 5. Monitoring and Alerting
```typescript
@Injectable ()
export class SecurityMonitoringService {
async monitorWebhookSecurity(request: Request, response: any) {
const metrics = {
sourceIp: request.ip,
2025-09-09 18:19:54 +09:00
userAgent: request.headers["user-agent"],
2025-09-02 16:09:17 +09:00
timestamp: new Date(),
success: response.success,
processingTime: response.processingTime,
};
// Alert on suspicious patterns
if (this.detectSuspiciousActivity(metrics)) {
await this.sendSecurityAlert(metrics);
}
// Log for audit
2025-09-09 18:19:54 +09:00
this.logger.log("Webhook security metrics", metrics);
2025-09-02 16:09:17 +09:00
}
private detectSuspiciousActivity(metrics: any): boolean {
// Implement your security detection logic
// - Too many requests from same IP
// - Unusual timing patterns
// - Failed authentication attempts
return false;
}
}
```
## 7. Production Deployment
### Environment Variables
2025-09-09 18:19:54 +09:00
2025-09-02 16:09:17 +09:00
```bash
2025-09-06 10:01:44 +09:00
# Platform Events
SF_EVENTS_ENABLED=true
SF_PROVISION_EVENT_CHANNEL=/event/OrderProvisionRequested__e
SF_EVENTS_REPLAY=LATEST
2025-09-02 16:09:17 +09:00
# Encryption
FIELD_ENCRYPTION_KEY=your_field_encryption_master_key
ENCRYPTION_KEY_ROTATION_DAYS=90
# Monitoring
SECURITY_ALERT_WEBHOOK=https://your-monitoring-service.com/alerts
AUDIT_LOG_RETENTION_DAYS=2555 # 7 years for compliance
```
### Salesforce Named Credential Setup
2025-09-09 18:19:54 +09:00
2025-09-06 10:01:44 +09:00
Not required for the event-driven provisioning path (the portal pulls events).
2025-09-02 16:09:17 +09:00
This guide provides a comprehensive, production-ready approach to secure Salesforce-Portal integration that builds on your existing security infrastructure while adding enterprise-grade protection for sensitive data transmission.