Skill站外收录 @skilllib/skill-2117939930272411685
customerio-security-basics
提供 Customer.io 集成的安全实施能力,涵盖密钥安全存储、PII 数据脱敏与哈希处理、API 密钥定期轮换、Webhook 签名验证、基于角色的最小权限访问控制,以及 GDPR/CCPA 合规的用户数据删除与匿名化支持。
测试与安全 AI 技能
Skills.MD
# Customer.io Security Basics
## Overview
Implement security best practices for Customer.io integrations including credential management, PII handling, and access controls.
## Prerequisites
- Customer.io account with admin access
- Understanding of your data classification
- Environment variable management
## Instructions
### Step 1: Secure Credential Management
```typescript
// lib/secrets.ts
import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
// Use a secrets manager instead of env vars for production
async function getCustomerIOCredentials(): Promise<{
siteId: string;
apiKey: string;
}> {
// Option 1: Google Cloud Secret Manager
const client = new SecretManagerServiceClient();
const [siteIdVersion] = await client.accessSecretVersion({
name: 'projects/PROJECT_ID/secrets/customerio-site-id/versions/latest'
});
const [apiKeyVersion] = await client.accessSecretVersion({
name: 'projects/PROJECT_ID/secrets/customerio-api-key/versions/latest'
});
return {
siteId: siteIdVersion.payload?.data?.toString() || '',
apiKey: apiKeyVersion.payload?.data?.toString() || ''
};
}
// Option 2: AWS Secrets Manager
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
async function getCredentialsFromAWS() {
const client = new SecretsManager({ region: 'us-east-1' });
const response = await client.getSecretValue({
SecretId: 'customerio-credentials'
});
return JSON.parse(response.SecretString || '{}');
}
```
### Step 2: PII Data Handling
```typescript
// lib/pii-handler.ts
import crypto from 'crypto';
// Hash sensitive identifiers before sending
function hashPII(value: string): string {
return crypto
.createHash('sha256')
.update(value + process.env.PII_SALT)
.digest('hex');
}
// Sanitize attributes before sending to Customer.io
function sanitizeUserAttributes(attributes: Record<string, any>): Record<string, any> {
const sensitiveFields = ['ssn', 'credit_card', 'password', 'bank_account'];
const piiFields = ['phone', 'address', 'date_of_birth'];
const sanitized = { ...attributes };
// Remove highly sensitive fields
for (const field of sensitiveFields) {
delete sanitized[field];
}
// Hash PII fields if needed for matching but not display
for (const field of piiFields) {
if (sanitized[field]) {
sanitized[`${field}_hash`] = hashPII(sanitized[field]);
// Optionally remove plain text version
// delete sanitized[field];
}
}
return sanitized;
}
// Usage
const safeAttributes = sanitizeUserAttributes({
email: 'user@example.com',
phone: '+1234567890',
ssn: '123-45-6789', // Will be removed
plan: 'premium'
});
```
### Step 3: API Key Rotation
```typescript
// scripts/rotate-api-key.ts
async function rotateAPIKey(): Promise<void> {
console.log('API Key Rotation Checklist:');
console.log('1. Generate new API key in Customer.io dashboard');
console.log('2. Update secrets manager with new key');
console.log('3. Deploy application with new key');
console.log('4. Verify integration works with new key');
console.log('5. Revoke old API key in dashboard');
console.log('6. Update documentation');
// Automated rotation (if using secrets manager)
// 1. Create new key via API (if supported)
// 2. Update secret in manager
// 3. Wait for propagation
// 4. Revoke old key
}
// Schedule rotation every 90 days
// Add to cron or scheduled task
```
### Step 4: Webhook Security
```typescript
// lib/webhook-security.ts
import crypto from 'crypto';
import { Request, Response, NextFunction } from 'express';
// Verify Customer.io webhook signatures
function verifyWebhookSignature(
payload: string,
signature: string,
secret: string
): boolean {
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expectedSignature)
);
}
// Express middleware for webhook verification
export function webhookAuthMiddleware(webhookSecret: string) {
return (req: Request, res: Response, next: NextFunction) => {
const signature = req.headers['x-cio-signature'] as string;
if (!signature) {
return res.status(401).json({ error: 'Missing signature' });
}
const payload = JSON.stringify(req.body);
if (!verifyWebhookSignature(payload, signature, webhookSecret)) {
return res.status(401).json({ error: 'Invalid signature' });
}
next();
};
}
// Usage
app.post('/webhooks/customerio',
webhookAuthMiddleware(process.env.CUSTOMERIO_WEBHOOK_SECRET!),
(req, res) => {
// Handle verified webhook
}
);
```
### Step 5: Access Control
```typescript
// lib/access-control.ts
interface TeamMember {
email: string;
role: 'admin' | 'editor' | 'viewer';
permissions: string[];
}
// Recommended role-based access
const rolePermissions = {
admin: [
'manage_api_keys',
'manage_team',
'manage_integrations',
'view_all_data',
'send_campaigns'
],
editor: [
'create_campaigns',
'edit_campaigns',
'view_analytics',
'manage_segments'
],
viewer: [
'view_campaigns',
'view_analytics'
]
};
// Audit logging for security-sensitive operations
function logSecurityEvent(event: {
action: string;
actor: string;
resource: string;
details?: Record<string, any>;
}) {
console.log(JSON.stringify({
type: 'security_audit',
timestamp: new Date().toISOString(),
...event
}));
}
```
### Step 6: Data Retention
```typescript
// lib/data-retention.ts
import { APIClient } from '@customerio/track';
// Suppress/delete users for GDPR/CCPA compliance
async function deleteUserData(client: APIClient, userId: string) {
// 1. Suppress the user (stops all messaging)
await client.suppress(userId);
// 2. Request full deletion through Customer.io dashboard or API
// Note: Full deletion may require support ticket
console.log(`User ${userId} suppressed and deletion requested`);
}
// Anonymous historical data retention
function anonymizeForAnalytics(userData: Record<string, any>) {
return {
...userData,
email: undefined,
phone: undefined,
first_name: undefined,
last_name: undefined,
// Keep aggregated/analytical data
plan: userData.plan,
signup_date: userData.created_at,
total_events: userData.event_count
};
}
```
## Security Checklist
- [ ] API keys stored in secrets manager (not env vars in code)
- [ ] API keys rotated every 90 days
- [ ] Webhook signatures verified
- [ ] PII sanitized before sending
- [ ] Minimum necessary data sent to Customer.io
- [ ] Team access follows least-privilege principle
- [ ] Audit logging enabled for sensitive operations
- [ ] GDPR/CCPA deletion process documented
- [ ] SSL/TLS enforced for all API calls
## Error Handling
| Issue | Solution |
|-------|----------|
| Exposed credentials | Rotate immediately, audit access |
| PII leak | Delete from Customer.io, notify DPO |
| Unauthorized access | Review access logs, revoke access |
## Resources
- [Customer.io Security](https://customer.io/security/)
- [GDPR Compliance](https://customer.io/docs/gdpr/)
- [Suppression API](https://customer.io/docs/api/track/#operation/suppress)
## Next Steps
After implementing security, proceed to `customerio-prod-checklist` for production readiness.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「customerio-security-basics」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次