PHP Security

Enforce PHP security standards for database access, password handling, and input validation.

51|6|Updated Mar 28, 2019
One-click install
npx skills add https://github.com/Mte90/dotfiles --skill php-security
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: PHP Security
Source: https://github.com/Mte90/dotfiles/tree/main/.config/opencode/skills/php/security
Command: npx skills add https://github.com/Mte90/dotfiles --skill php-security

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write more secure PHP code by enforcing best practices for database interactions, password management, and input validation, preventing common vulnerabilities like SQL injection and XSS.

Core Features & Use Cases

  • Database Security: Ensures safe database queries using prepared statements with PDO.
  • Password Protection: Implements strong password hashing and verification.
  • Input Validation & Output Escaping: Protects against cross-site scripting (XSS) and ensures data integrity.
  • Use Case: A developer can use this skill to audit their PHP codebase for security flaws, ensuring all user inputs are sanitized and sensitive data is handled securely.

Quick Start

Apply PHP security standards to the provided code snippet.

Frequently Asked Questions about PHP Security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent SQL injection in PHP using PDO?

To prevent SQL injection in PHP, use PDO prepared statements instead of raw SQL concatenation. Prepared statements separate SQL logic from data input, ensuring user-supplied values are treated strictly as data and cannot execute malicious database commands.

What is the best way to hash passwords in PHP for secure storage?

The best way to hash passwords in PHP is using Argon2id hashing. This modern algorithm provides robust protection against brute-force attacks by utilizing memory-hard computations, ensuring sensitive credentials remain securely encrypted during storage and verification.

How do I protect against cross-site scripting (XSS) when handling input validation in PHP?

To protect against cross-site scripting (XSS) in PHP, apply strict input validation and proper output escaping. Sanitizing user inputs ensures data integrity, while escaping output prevents malicious scripts from executing in the browser.

Does this PHP security approach work with existing legacy codebases?

Yes, this PHP security approach works with existing legacy codebases by auditing snippets for security flaws. It identifies insecure anti-patterns like raw SQL concatenation and weak hashing, guiding developers to refactor and enforce modern standards.

Why should I avoid raw SQL concatenation when writing PHP database queries?

You should avoid raw SQL concatenation in PHP database queries because it directly exposes your application to SQL injection vulnerabilities. Using PDO prepared statements safely separates query structure from data, neutralizing malicious database manipulation attempts.