From caio-build-harness
Patterns for GDPR/CCPA compliance — data minimization, purpose limitation, retention policies, right-to-erasure workflows, PII audit checklists, and data processing agreements. Use when handling personal data storage or processing — not for consent banners (use gdpr-consent) or general security hardening.
How this skill is triggered — by the user, by Claude, or both
Slash command
/caio-build-harness:data-protectionThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Legal compliance and data handling for CAIO projects. Getting this wrong means lawsuits, fines, and career-ending incidents.
Legal compliance and data handling for CAIO projects. Getting this wrong means lawsuits, fines, and career-ending incidents.
Only collect what you need. If you don't have it, you can't lose it.
Use data only for the stated purpose. No "we might need this later."
Don't keep data forever. Define retention periods.
Protect data from unauthorized access, loss, or destruction.
// ✅ Collect minimum required data
const registrationSchema = z.object({
email: z.string().email(), // Required for auth
name: z.string().optional(), // Only if needed for personalization
// ❌ DON'T collect: DOB, address, phone unless required
});
// ✅ Clear consent mechanism
interface ConsentRecord {
userId: string;
consentType: "terms" | "privacy" | "marketing";
consentGiven: boolean;
timestamp: Date;
ipAddress: string; // For audit trail
version: string; // Which policy version they agreed to
}
// schema.prisma
model User {
id String @id @default(cuid())
email String @unique
name String?
// Soft delete - NEVER hard delete user data
deletedAt DateTime?
// Audit trail
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Consent tracking
consents Consent[]
}
model Consent {
id String @id @default(cuid())
userId String
type String // 'terms', 'privacy', 'marketing'
given Boolean
version String // Policy version
ipAddress String
timestamp DateTime @default(now())
user User @relation(fields: [userId], references: [id])
}
// lib/audit-log.ts
import { logger } from "./logger";
type DataAccessEvent = {
userId: string;
action: "view" | "export" | "modify" | "delete";
dataType: string;
targetId?: string;
reason?: string;
};
export function logDataAccess(event: DataAccessEvent) {
logger.info(
{
type: "data_access",
...event,
timestamp: new Date().toISOString(),
},
`Data access: ${event.action} ${event.dataType}`,
);
}
// Usage
logDataAccess({
userId: session.user.id,
action: "view",
dataType: "user_profile",
targetId: targetUserId,
});
Every app needs:
Location: /privacy or footer link
// components/CookieBanner.tsx
'use client'
import { useState, useEffect } from 'react'
export function CookieBanner() {
const [showBanner, setShowBanner] = useState(false)
useEffect(() => {
const consent = localStorage.getItem('cookie-consent')
if (!consent) setShowBanner(true)
}, [])
const accept = (level: 'essential' | 'all') => {
localStorage.setItem('cookie-consent', JSON.stringify({
level,
timestamp: new Date().toISOString(),
}))
setShowBanner(false)
if (level === 'all') {
// Enable analytics, marketing cookies
}
}
if (!showBanner) return null
return (
<div className="fixed bottom-0 w-full bg-white border-t p-4">
<p>We use cookies to improve your experience.</p>
<div className="flex gap-2 mt-2">
<button onClick={() => accept('essential')}>
Essential Only
</button>
<button onClick={() => accept('all')}>
Accept All
</button>
</div>
</div>
)
}
// app/api/user/export/route.ts
import { auth } from "@/lib/auth";
import { db } from "@/lib/db";
import { NextResponse } from "next/server";
export async function GET() {
const session = await auth();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// Gather all user data
const userData = await db.user.findUnique({
where: { id: session.user.id },
include: {
posts: true,
comments: true,
consents: true,
// Include all related data
},
});
// Log the export
logDataAccess({
userId: session.user.id,
action: "export",
dataType: "full_profile",
});
return NextResponse.json(
{
exportedAt: new Date().toISOString(),
data: userData,
},
{
headers: {
"Content-Disposition": `attachment; filename="user-data-${session.user.id}.json"`,
},
},
);
}
// app/api/user/delete/route.ts
import { auth } from "@/lib/auth";
import { db } from "@/lib/db";
import { NextResponse } from "next/server";
export async function DELETE() {
const session = await auth();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// Soft delete - preserve for audit trail
await db.user.update({
where: { id: session.user.id },
data: {
deletedAt: new Date(),
// Anonymize PII
email: `deleted-${session.user.id}@anonymized.local`,
name: null,
},
});
// Log the deletion
logDataAccess({
userId: session.user.id,
action: "delete",
dataType: "account",
reason: "user_request",
});
// Clear session
// signOut()
return NextResponse.json({ success: true });
}
// scripts/cleanup-old-data.ts
// Run as cron job
import { db } from "@/lib/db";
const RETENTION_PERIODS = {
deletedUsers: 90, // Days after soft delete
sessions: 30, // Inactive sessions
auditLogs: 365, // Keep audit logs for 1 year
analytics: 180, // Anonymized analytics
};
async function cleanupOldData() {
const now = new Date();
// Remove permanently deleted users after retention period
const deleteThreshold = new Date(
now.getTime() - RETENTION_PERIODS.deletedUsers * 24 * 60 * 60 * 1000,
);
await db.user.deleteMany({
where: {
deletedAt: {
lt: deleteThreshold,
},
},
});
// Clean up old sessions
const sessionThreshold = new Date(
now.getTime() - RETENTION_PERIODS.sessions * 24 * 60 * 60 * 1000,
);
await db.session.deleteMany({
where: {
updatedAt: {
lt: sessionThreshold,
},
},
});
console.log("Data cleanup completed");
}
// ❌ BAD
logger.info({ email: user.email, name: user.name }, "User logged in");
// ✅ GOOD
logger.info({ userId: user.id }, "User logged in");
// ❌ BAD
await db.user.create({
data: { password: req.body.password },
});
// ✅ GOOD
import { hash } from "bcrypt";
await db.user.create({
data: { passwordHash: await hash(req.body.password, 12) },
});
// ❌ BAD - Sending to analytics without consent
trackEvent("signup", { email: user.email });
// ✅ GOOD - Check consent first
if (hasConsent(user.id, "analytics")) {
trackEvent("signup", { userId: user.id });
}
// ❌ BAD - Sequential IDs leak data
/api/users/1
/api/users/2
// ✅ GOOD - UUIDs don't reveal count
/api/users/550e8400-e29b-41d4-a716-446655440000
Before using any third-party service:
| Common Vendors | GDPR DPA | Data Location |
|---|---|---|
| Vercel | Yes | US/EU option |
| Supabase | Yes | US/EU option |
| Stripe | Yes | US/EU |
| Sentry | Yes | US/EU option |
| PostHog | Yes | US/EU option |
If user data is exposed:
GDPR breach notification template:
To: [Data Protection Authority]
Subject: Data Breach Notification - [Company Name]
Date of breach: [Date]
Date discovered: [Date]
Nature of breach: [Description]
Categories of data: [What was exposed]
Approximate number of users: [Count]
Likely consequences: [Impact assessment]
Measures taken: [Response actions]
Contact: [DPO or responsible person]
| Requirement | Implementation | Location |
|---|---|---|
| Privacy policy | Static page | /privacy |
| Cookie consent | Banner component | Layout |
| Data export | API endpoint | /api/user/export |
| Account deletion | API endpoint | /api/user/delete |
| Soft delete | Prisma schema | deletedAt field |
| Audit logging | Logger wrapper | logDataAccess() |
| Consent tracking | Database table | Consent model |
npx claudepluginhub get-caio/harness --plugin caio-build-harnessProvides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.