php-security
БесплатноБез исполняемых скриптовНе проверенPHP application security: vulnerability review and secure implementation patterns. USE WHEN: securing PHP applications, reviewing code for vulnerabilities, or…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
PHP Security Skill
USE WHEN: Securing PHP applications, reviewing code for vulnerabilities, or implementing security best practices. DO NOT USE FOR: Code quality issues (use php-quality), general PHP development patterns.
OWASP Top 10 for PHP
A01: Broken Access Control
// Bad: IDOR vulnerability
public function getOrder(int $orderId): Order {
return $this->orderRepository->find($orderId); // No ownership check!
}
// Good: Ownership verification
public function getOrder(int $orderId, User $currentUser): Order {
$order = $this->orderRepository->find($orderId);
if ($order->getUserId() !== $currentUser->getId() &&
!$currentUser->hasRole('ADMIN')) {
throw new AccessDeniedException('Cannot access this order');
}
return $order;
}
// Good: Using Symfony voters
#[IsGranted('VIEW', subject: 'order')]
public function show(Order $order): Response {
return $this->render('order/show.html.twig', ['order' => $order]);
}
A03: Injection
// Bad: SQL Injection
$query = "SELECT * FROM users WHERE id = " . $_GET['id'];
$result = $pdo->query($query);
// Good: Prepared statements (PDO)
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");
$stmt->execute(['id' => $_GET['id']]);
// Good: Doctrine DQL
$user = $entityManager->createQuery(
'SELECT u FROM User u WHERE u.email = :email'
)->setParameter('email', $email)->getOneOrNullResult();
// Bad: Command injection
exec("ls " . $_GET['dir']);
// Good: escapeshellarg or avoid shell entirely
$dir = escapeshellarg($_GET['dir']);
exec("ls $dir");
// Better: Use PHP functions instead of shell
$files = scandir($_GET['dir']); // Still validate path!
A04: Cryptographic Failures
// Bad: MD5 for passwords
$hash = md5($password);
// Good: password_hash with Argon2id
$hash = password_hash($password, PASSWORD_ARGON2ID, [
'memory_cost' => 65536,
'time_cost' => 4,
'threads' => 3,
]);
// Verify password
if (!password_verify($inputPassword, $storedHash)) {
throw new AuthenticationException('Invalid credentials');
}
// Good: Secure random generation
$token = bin2hex(random_bytes(32));
$apiKey = base64_encode(random_bytes(24));
// Good: Encryption with libsodium
$key = sodium_crypto_secretbox_keygen();
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$encrypted = sodium_crypto_secretbox($plaintext, $nonce, $key);
$decrypted = sodium_crypto_secretbox_open($encrypted, $nonce, $key);
A05: XSS Prevention
// Bad: Direct output
echo "<div>" . $_GET['name'] . "</div>";
// Good: Escape output
echo "<div>" . htmlspecialchars($_GET['name'], ENT_QUOTES, 'UTF-8') . "</div>";
// Good: Twig auto-escaping (enabled by default)
{{ user.name }} {# Automatically escaped #}
{{ user.bio|raw }} {# Only use raw when content is trusted #}
// Good: Content Security Policy
header("Content-Security-Policy: default-src 'self'; script-src 'self'");
A07: Authentication Failures
// Good: Secure session configuration
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_secure', 1);
ini_set('session.cookie_samesite', 'Strict');
ini_set('session.use_strict_mode', 1);
ini_set('session.sid_length', 48);
// Good: Session regeneration after login
session_regenerate_id(true);
// Good: Rate limiting with Symfony
use Symfony\Component\RateLimiter\RateLimiterFactory;
public function login(RateLimiterFactory $loginLimiter): Response {
$limiter = $loginLimiter->create($request->getClientIp());
if (!$limiter->consume()->isAccepted()) {
throw new TooManyRequestsHttpException();
}
// Process login
}
// Good: Timing-safe comparison
if (!hash_equals($storedToken, $inputToken)) {
throw new InvalidTokenException();
}
A08: Software Integrity
// Good: Verify file uploads
$allowedMimeTypes = ['image/jpeg', 'image/png', 'image/gif'];
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->file($_FILES['upload']['tmp_name']);
if (!in_array($mimeType, $allowedMimeTypes, true)) {
throw new InvalidArgumentException('Invalid file type');
}
// Good: Secure deserialization - NEVER unserialize untrusted data
// Use JSON instead
$data = json_decode($input, true, 512, JSON_THROW_ON_ERROR);
// If you must use unserialize, use allowed_classes
$data = unserialize($input, ['allowed_classes' => [AllowedClass::class]]);
Framework-Specific Security
Laravel Security
// CSRF protection (automatic in forms)
@csrf
// Mass assignment protection
class User extends Model {
protected $fillable = ['name', 'email']; // Whitelist
// OR
protected $guarded = ['id', 'is_admin']; // Blacklist
}
// Query scopes for authorization
public function scopeForUser(Builder $query, User $user): Builder {
return $query->where('user_id', $user->id);
}
// Validation
$validated = $request->validate([
'email' => 'required|email:rfc,dns|unique:users',
'password' => 'required|min:12|confirmed',
Установить php-security в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobBashFAQ
Что делает скилл php-security?
PHP application security: vulnerability review and secure implementation patterns. USE WHEN: securing PHP applications, reviewing code for vulnerabilities, or implementing security best practices DO NOT USE FOR: code quality issues (use `php-quality`), general PHP development patterns
Как установить скилл php-security?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл php-security запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic