Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

secure-error-handling

БесплатноБез исполняемых скриптовНе проверен

Implement secure error handling to prevent information leakage and provide appropriate error responses. Use this skill when you need to handle errors in API…

harperaaот harperaa★ 19 звёзд на GitHub7 установок в других каталогах

Об этом скилле

Secure Error Handling - Preventing Information Leakage

The Error Message Problem

Error messages are designed to help developers debug. But in production, detailed errors help attackers more than they help users.

What Attackers Learn from Error Messages

Database structure:

Error: column 'credit_cards.number' does not exist

→ Attacker now knows you have a credit_cards table

File paths:

Error at /var/www/app/lib/payment.js:47

→ Attacker learns your directory structure

Dependencies:

Stripe API error: Invalid API key format

→ Attacker knows you use Stripe

System info:

PostgreSQL 9.4 connection failed

→ Attacker learns your database version and can look up known vulnerabilities

Real-World Information Leakage

According to SANS Institute research, 74% of successful attacks start with reconnaissance phase where attackers gather information about the target system. Error messages are a primary source of this intelligence.

Equifax Breach (2017): Detailed error messages revealed they were using Apache Struts with a known vulnerability. Attackers exploited this revealed information.

Our Error Handling Architecture

Environment-Aware Error Responses

Development Mode:

{
  error: "Database connection failed",
  stack: "Error: connection timeout at db.connect (database.js:42:15)...",
  context: "user-profile-update",
  timestamp: "2025-10-15T10:30:00Z"
}

→ Developers get full details for debugging

Production Mode:

{
  error: "Internal server error",
  message: "An unexpected error occurred. Please try again later."
}

→ Users get safe, generic message

The Logging Strategy

All errors are logged server-side with full details (for investigation), but only generic messages are sent to clients in production. This gives us debugging capability without information leakage.

Implementation Files

  • lib/errorHandler.ts - 5 error handlers for different scenarios

Available Error Handlers

1. handleApiError(error, context)

Use for: Unexpected errors (HTTP 500)

import { handleApiError } from '@/lib/errorHandler';

async function handler(request: NextRequest) {
  try {
    // Risky operation
    await processPayment(data);
    return NextResponse.json({ success: true });

  } catch (error) {
    return handleApiError(error, 'payment-processing');
    // Production: "Internal server error"
    // Development: Full stack trace
  }
}

Returns:

  • Development: Full error with stack trace
  • Production: Generic "Internal server error" message
  • HTTP Status: 500

2. handleValidationError(message, details)

Use for: Input validation failures (HTTP 400)

import { handleValidationError } from '@/lib/errorHandler';

if (!isValidEmail(email)) {
  return handleValidationError(
    'Validation failed',
    { email: 'Invalid email format' }
  );
}

Returns:

{
  "error": "Validation failed",
  "details": {
    "email": "Invalid email format"
  }
}
  • HTTP Status: 400
  • Both dev and production: Returns detailed field errors (helps users fix input)

3. handleForbiddenError(message)

Use for: Authorization failures (HTTP 403)

import { handleForbiddenError } from '@/lib/errorHandler';

// Check if user owns this resource
if (resource.userId !== userId) {
  return handleForbiddenError('You do not have access to this resource');
}

Returns:

{
  "error": "Forbidden",
  "message": "You do not have access to this resource"
}
  • HTTP Status: 403
  • Both dev and production: Returns the provided message

4. handleUnauthorizedError(message)

Use for: Authentication failures (HTTP 401)

import { handleUnauthorizedError } from '@/lib/errorHandler';
import { auth } from '@clerk/nextjs/server';

const { userId } = await auth();
if (!userId) {
  return handleUnauthorizedError('Authentication required');
}

Returns:

{
  "error": "Unauthorized",
  "message": "Authentication required"
}
  • HTTP Status: 401
  • Both dev and production: Returns the provided message
  • Default message: "Authentication required" if no message provided

5. handleNotFoundError(resource)

Use for: Resource not found (HTTP 404)

import { handleNotFoundError } from '@/lib/errorHandler';

const post = await db.posts.findOne({ id: postId });
if (!post) {
  return handleNotFoundError('Post');
}

Returns:

{
  "error": "Not found",
  "message": "Post not found"
}
  • HTTP Status: 404
  • Both dev and production: Returns resource-specific message

Complete Error Handling Examples

Example 1: Protected API Route with Full Error Handling

// app/api/posts/[id]/route.ts
import { NextRequest, NextResponse } from 'next/server';
import { auth } from '@clerk/nextjs/server';
import { validateReques
Полный SKILL.md на GitHub

Установить secure-error-handling в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл secure-error-handling?

Implement secure error handling to prevent information leakage and provide appropriate error responses. Use this skill when you need to handle errors in API routes, prevent stack trace exposure, implement environment-aware error messages, or use the error handler utilities. Triggers include "error handling", "handle errors", "error messages", "information leakage", "stack trace", "handleApiError", "production errors", "error responses".

Как установить скилл secure-error-handling?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл secure-error-handling запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить secure-error-handling с