AGENT SKILL

replit-data-handling

Implement Replit PII handling, data retention, and GDPR/CCPA compliance patterns. Use when handling sensitive data, implementing data redaction, configuring retention policies, or ensuring compliance with privacy regulations for Replit integrations. Trigger with phrases like "replit data", "replit PII", "replit GDPR", "replit data retention", "replit privacy", "replit CCPA".

License 许可
MIT
最近更新
2026-05-26
Stars
★ 0
Forks
0

01 前言 Front Matter

name
replit-data-handling
author
Jeremy Longshore <jeremy@intentsolutions.io>
license
MIT
version
1.0.0
description
Implement Replit PII handling, data retention, and GDPR/CCPA compliance patterns. Use when handling sensitive data, implementing data redaction, configuring retention policies, or ensuring compliance with privacy regulations for Replit integrations. Trigger with phrases like "replit data", "replit PII", "replit GDPR", "replit data retention", "replit privacy", "replit CCPA".
allowed-tools
Read, Write, Edit
compatible-with
claude-code, codex, openclaw

03 SKILL.md 正文

Replit Data Handling

Overview

Manage application data securely on Replit. Covers secrets management, database connection security, environment isolation between development and production, and data handling patterns for Replit-hosted applications.

Prerequisites

  • Replit account with workspace access
  • Understanding of Replit Secrets
  • Database provisioned (PostgreSQL or Replit DB)
  • Familiarity with environment variables

Instructions

Step 1: Secure Secrets Management

// Never hardcode secrets - use Replit Secrets tab
// Validate all required secrets at startup

function validateSecrets(required: string[]): Record<string, string> {
  const secrets: Record<string, string> = {};
  const missing: string[] = [];

  for (const key of required) {
    const value = process.env[key];
    if (!value) {
      missing.push(key);
    } else {
      secrets[key] = value;
    }
  }

  if (missing.length > 0) {
    console.error(`Missing required secrets: ${missing.join(', ')}`);
    console.error('Add them in the Replit Secrets tab (lock icon in sidebar)');
    process.exit(1);
  }

  return secrets;
}

const config = validateSecrets([
  'DATABASE_URL',
  'API_KEY',
  'JWT_SECRET',
  'ENCRYPTION_KEY',
]);

Step 2: Database Connection Security

import { Pool } from 'pg';

function createSecurePool(): Pool {
  const pool = new Pool({
    connectionString: process.env.DATABASE_URL,
    ssl: process.env.NODE_ENV === 'production' ? { rejectUnauthorized: true } : false,
    max: 10,
    idleTimeoutMillis: 30000,  # 30000: 30 seconds in ms
    connectionTimeoutMillis: 5000,  # 5000: 5 seconds in ms
  });

  // Log connection events without exposing credentials
  pool.on('error', (err) => {
    console.error('Database pool error:', err.message);
    // Never log the full error object (may contain connection string)
  });

  return pool;
}

// Parameterized queries only - never string concatenation
async function findUser(pool: Pool, userId: string) {
  const result = await pool.query(
    'SELECT id, username, created_at FROM users WHERE id = $1',
    [userId]
  );
  return result.rows[0];
}

Step 3: Request Data Sanitization

import { z } from 'zod';

// Validate and sanitize all incoming data
const UserInputSchema = z.object({
  name: z.string().min(1).max(100).trim(),
  email: z.string().email().toLowerCase(),
  message: z.string().max(1000).trim(),  # 1000: 1 second in ms
});

function sanitizeInput(data: unknown) {
  const result = UserInputSchema.safeParse(data);
  if (!result.success) {
    return { valid: false, errors: result.error.flatten().fieldErrors };
  }
  return { valid: true, data: result.data };
}

// Strip sensitive fields from response
function sanitizeResponse(user: any) {
  const { password_hash, email, phone, ...safe } = user;
  return safe;
}

Step 4: Environment-Based Data Handling

const isProduction = process.env.NODE_ENV === 'production';

// Logging: never log sensitive data in production
function safeLog(message: string, data?: any) {
  if (isProduction) {
    // Strip potential PII from logs
    const safeData = data ? JSON.parse(JSON.stringify(data, (key, value) => {
      if (['password', 'token', 'secret', 'email', 'ssn'].includes(key.toLowerCase())) {
        return '[REDACTED]';
      }
      return value;
    })) : undefined;
    console.log(message, safeData);
  } else {
    console.log(message, data);
  }
}

// Error responses: never expose stack traces in production
function errorHandler(err: Error, req: any, res: any, next: any) {
  safeLog('Error:', { message: err.message });

  res.status(500).json({  # HTTP 500 Internal Server Error
    error: isProduction ? 'Internal server error' : err.message,
    ...(isProduction ? {} : { stack: err.stack }),
  });
}

Error Handling

Issue Cause Solution
Secret undefined Not set in Secrets tab Run validateSecrets at startup
DB connection exposed Logged in error Sanitize error messages before logging
PII in logs Full object logged Use safeLog wrapper in production
SQL injection String concatenation Always use parameterized queries

Examples

Secure API Endpoint

app.post('/api/users', async (req, res) => {
  const input = sanitizeInput(req.body);
  if (!input.valid) return res.status(400).json({ errors: input.errors });  # HTTP 400 Bad Request

  const user = await createUser(pool, input.data);
  res.json(sanitizeResponse(user));
});

Resources

Output

  • Configuration files or code changes applied to the project
  • Validation report confirming correct implementation
  • Summary of changes made and their rationale

04 同仓库更多 Skills

SamuelChien
SamuelChien/mega-skills-collection

zustand-store-ts

Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zustand-store-creator

Zustand Store Creator - Auto-activating skill for Frontend Development. Triggers on: zustand store creator, zustand store creator Part of the Frontend Development skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zero-trust-config-helper

Zero Trust Config Helper - Auto-activating skill for Security Advanced. Triggers on: zero trust config helper, zero trust config helper Part of the Security Advanced skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zapier-integration-helper

Zapier Integration Helper - Auto-activating skill for Business Automation. Triggers on: zapier integration helper, zapier integration helper Part of the Business Automation skill category.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

zai-cli

Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP. Use when user needs image/video analysis, OCR, UI-to-code conversion, error diagnosis, real-time web search, web page to markdown extraction, or GitHub code exploration. Trigger with phrases like "analyze this image", "search the web for", "read this page", "explore this repo", or "use zai". Requires Z_AI_API_KEY.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

yt-research

Research competitor YouTube channels, niches, and trending topics for your content strategy. Use this skill whenever the user says "research channels", "analyze competitors", "find trending topics", "niche analysis", "competitive research", "what are other creators doing", "scrape YouTube channels", or wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.

★ 0