Langsung ke konten
Skillpedia
Keamanan12k Β· #11454

secure-code-guardian

Fungsinya

Skill ini memandu AI untuk membangun fitur aman seperti masuk, kontrol akses, dan validasi input. Skill ini untuk pengembang yang menginginkan kode yang lebih aman.

Kapan dipakai

  • βœ“Saat Anda menambahkan sistem login atau pendaftaran ke aplikasi web.
  • βœ“Saat Anda ingin input pengguna diperiksa dari serangan seperti SQL injection atau cross-site scripting.
  • βœ“Saat Anda perlu penyimpanan kata sandi yang aman, token, atau header CORS diatur.

Link skill

https://github.com/Jeffallan/claude-skills/blob/main/skills/secure-code-guardian/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/Jeffallan/claude-skills/blob/main/skills/secure-code-guardian/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBisakah Anda membantu saya menambahkan login yang aman dan penyimpanan kata sandi ke aplikasi web saya?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

AI mengikuti daftar periksa: merencanakan risiko, membangun perlindungan, lalu menguji bahwa serangan umum diblokir dan keputusan dicatat.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Secure Code Guardian

Core Workflow

  1. Threat model β€” Identify attack surface and threats
  2. Design β€” Plan security controls
  3. Implement β€” Write secure code with defense in depth; see code examples below
  4. Validate β€” Test security controls with explicit checkpoints (see below)
  5. Document β€” Record security decisions

Validation Checkpoints

After each implementation step, verify:

  • Authentication: Test brute-force protection (lockout/rate limit triggers), session fixation resistance, token expiration, and invalid-credential error messages (must not leak user existence).
  • Authorization: Verify horizontal and vertical privilege escalation paths are blocked; test with tokens belonging to different roles/users.
  • Input handling: Confirm SQL injection payloads (' OR 1=1--) are rejected; confirm XSS payloads (<script>alert(1)</script>) are escaped or rejected.
  • Headers/CORS: Validate with a security scanner (e.g., curl -I, Mozilla Observatory) that security headers are present and CORS origin allowlist is correct.

Reference Guide

Load detailed guidance based on context:

Topic Reference Load When
OWASP references/owasp-prevention.md OWASP Top 10 patterns
Authentication references/authentication.md Password hashing, JWT
Input Validation references/input-validation.md Zod, SQL injection
XSS/CSRF references/xss-csrf.md XSS prevention, CSRF
Headers references/security-headers.md Helmet, rate limiting

Constraints

MUST DO

  • Hash passwords with bcrypt/argon2 (never MD5/SHA-1/unsalted hashes)
  • Use parameterized queries (never string-interpolated SQL)
  • Validate and sanitize all user input before use
  • Implement rate limiting on auth endpoints
  • Set security headers (CSP, HSTS, X-Frame-Options)
  • Log security events (failed auth, privilege escalation attempts)
  • Store secrets in environment variables or secret managers (never in source code)

MUST NOT DO

  • Store passwords in plaintext or reversibly encrypted form
  • Trust user input without validation
  • Expose sensitive data in logs or error responses
  • Use weak or deprecated algorithms (MD5, SHA-1, DES, ECB mode)
  • Hardcode secrets or credentials in code

Code Examples

Password Hashing (bcrypt)

import bcrypt from 'bcrypt';

const SALT_ROUNDS = 12; // minimum 10; 12 balances security and performance

export async function hashPassword(plaintext: string): Promise<string> {
  return bcrypt.hash(plaintext, SALT_ROUNDS);
}

export async function verifyPassword(plaintext: string, hash: string): Promise<boolean> {
  return bcrypt.compare(plaintext, hash);
}

Parameterized SQL Query (Node.js / pg)

// NEVER: `SELECT * FROM users WHERE email = '${email}'`
// ALWAYS: use positional parameters
import { Pool } from 'pg';
const pool = new Pool();

export async function getUserByEmail(email: string) {
  const { rows } = await pool.query(
    'SELECT id, email, role FROM users WHERE email = $1',
    [email]  // value passed separately β€” never interpolated
  );
  return rows[0] ?? null;
}

Input Validation with Zod

import { z } from 'zod';

const LoginSchema = z.object({
  email: z.string().email().max(254),
  password: z.string().min(8).max(128),
});

export function validateLoginInput(raw: unknown) {
  const result = LoginSchema.safeParse(raw);
  if (!result.success) {
    // Return generic error β€” never echo raw input back
    throw new Error('Invalid credentials format');
  }
  return result.data;
}

JWT Validation

import jwt from 'jsonwebtoken';

const JWT_SECRET = process.env.JWT_SECRET!; // never hardcode

export function verifyToken(token: string): jwt.JwtPayload {
  // Throws if expired, tampered, or wrong algorithm
  const payload = jwt.verify(token, JWT_SECRET, {
    algorithms: ['HS256'],   // explicitly allowlist algorithm
    issuer: 'your-app',
    audience: 'your-app',
  });
  if (typeof payload === 'string') throw new Error('Invalid token payload');
  return payload;
}

Securing an Endpoint β€” Full Flow

import express from 'express';
import rateLimit from 'express-rate-limit';
import helmet from 'helmet';

const app = express();
app.use(helmet()); // sets CSP, HSTS, X-Frame-Options, etc.
app.use(express.json({ limit: '10kb' })); // limit payload size

const authLimiter = rateLimit({
  windowMs: 15 * 60 * 
Pertanyaan umum

Apakah skill ini bekerja dengan bahasa pemrograman apa pun?

Skill ini berfokus pada teknologi dan pola web yang umum, jadi contohnya paling cocok untuk aplikasi web biasa.

Apakah skill ini akan mengaudit seluruh aplikasi saya untuk celah keamanan?

Skill ini memeriksa kontrol yang dibangunnya, misalnya payload serangan yang diblokir dan batas percobaan login. Audit penuh dicakup oleh skill security reviewer.

Apakah skill ini mencakup penyimpanan kata sandi yang aman?

Ya, skill ini memandu penggunaan metode hashing seperti bcrypt atau argon2, bukan menyimpan kata sandi dalam teks biasa.

Detail

Deskripsi asli dari pembuat

Use when implementing authentication/authorization, securing user input, or preventing OWASP Top 10 vulnerabilities β€” including custom security implementations such as hashing passwords with bcrypt/argon2, sanitizing SQL queries with parameterized statements, configuring CORS/CSP headers, validating input with Zod, and setting up JWT tokens. Invoke for authentication, authorization, input validation, encryption, OWASP Top 10 prevention, secure session management, and security hardening. For pre-built OAuth/SSO integrations or standalone security audits, consider a more specialized skill.

repo: Jeffallan/claude-skills

Popularitas

Bintang GitHub
12k
Peringkat
#11454
Lisensi
MIT
Diperbarui
30/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa