Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

php-security

FreeNo executable scriptsNot checked

PHP application security: vulnerability review and secure implementation patterns. USE WHEN: securing PHP applications, reviewing code for vulnerabilities, or…

claude-dev-suiteby claude-dev-suite★ 51 GitHub stars

About this skill

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',
Full SKILL.md on GitHub

Install php-security in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

Read
Grep
Glob
Bash

FAQ

What does the php-security skill do?

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

How do I install the php-security skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the php-security skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare php-security with