/acc:check-path-traversalfrom acc
Analyzes PHP code for path traversal vulnerabilities. Detects directory traversal, file inclusion with user input, missing path validation, symlink attacks.
Ships in acc. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Analyze PHP code for path/directory traversal vulnerabilities (OWASP A01:2021).
// CRITICAL: Direct path from user
$content = file_get_contents($_GET['file']);
$content = file_get_contents('/uploads/' . $_GET['filename']);
// CRITICAL: File reading
$data = file($_POST['path']);
$lines = readfile($request->input('document'));
// CRITICAL: File writing
file_put_contents('/reports/' . $_GET['name'], $content);
// CRITICAL: File deletion
unlink('/uploads/' . $_POST['file']);
unlink($basePath . $userInput);
// CRITICAL: Local File Inclusion (LFI)
include $_GET['page'];
include 'templates/' . $_GET['template'] . '.php';
require $request->input('module');
// CRITICAL: Remote File Inclusion (RFI) if allow_url_include=On
include 'http://' . $_GET['host'] . '/script.php';
// CRITICAL: Dynamic class loading
$class = $_GET['type'];
require "classes/{$class}.php";
// CRITICAL: Basic traversal
$file = '/var/www/uploads/' . $_GET['name'];
// Input: ../../../etc/passwd
// Result: /var/www/uploads/../../../etc/passwd = /etc/passwd
// CRITICAL: Encoded traversal
// Input: ..%2F..%2F..%2Fetc/passwd (URL encoded)
// Input: ..%252f..%252f..%252fetc/passwd (double encoded)
// CRITICAL: Null byte injection (PHP < 5.3.4)
$file = '/templates/' . $_GET['name'] . '.php';
// Input: ../../../etc/passwd%00
// Result: /templates/../../../etc/passwd (null terminates string)
// CRITICAL: User-controlled upload path
$uploadDir = '/uploads/' . $_POST['folder'] . '/';
move_uploaded_file($tmp, $uploadDir . $filename);
// CRITICAL: Original filename used directly
$filename = $_FILES['upload']['name'];
move_uploaded_file($tmp, "/uploads/{$filename}");
// Filename: ../../../var/www/html/shell.php
// CRITICAL: Zip extraction without path validation
$zip = new ZipArchive();
$zip->open($_FILES['archive']['tmp_name']);
$zip->extractTo('/uploads/');
// Archive may contain: ../../var/www/html/malicious.php
// CRITICAL: Tar extraction
$phar = new PharData($uploadedFile);
$phar->extractTo('/uploads/');
// CRITICAL: Following symlinks
$realPath = '/uploads/' . $_GET['file'];
$content = file_get_contents($realPath);
// Attacker creates symlink: uploads/secret -> /etc/passwd
// CRITICAL: Checking existence without symlink validation
if (file_exists($userPath)) {
include $userPath;
}
// CRITICAL: Image path from user
$image = imagecreatefromjpeg('/images/' . $_GET['photo']);
// CRITICAL: PDF generation with user paths
$pdf->image('/assets/' . $_POST['logo']);
// CRITICAL: File download
$filepath = '/downloads/' . $_GET['file'];
header('Content-Disposition: attachment; filename="' . basename($filepath) . '"');
readfile($filepath);
// CRITICAL: Log file path manipulation
$logFile = '/var/log/' . $_GET['app'] . '.log';
$content = file_get_contents($logFile);
// CRITICAL: Log viewing
$logPath = "/logs/{$_GET['date']}/app.log";
return file($logPath);
// CRITICAL: Config path from user
$config = parse_ini_file('/config/' . $_GET['env'] . '.ini');
// CRITICAL: YAML loading
$yaml = yaml_parse_file('/config/' . $_POST['file']);
// CRITICAL: Backup destination from user
$backupPath = $_POST['backup_path'] . '/backup.sql';
file_put_contents($backupPath, $sqlDump);
// CRITICAL: Export path
$exportDir = '/exports/' . $_GET['folder'];
mkdir($exportDir, 0777, true);
# File operations with variable
Grep: "(file_get_contents|file_put_contents|fopen|readfile|file)\s*\([^)]*\\\$" --glob "**/*.php"
# Include/require with variable
Grep: "(include|require|include_once|require_once)\s+[^;]*\\\$" --glob "**/*.php"
# Path concatenation
Grep: "(/uploads/|/downloads/|/files/|/images/).*\\\$" --glob "**/*.php"
# Unlink/delete with variable
Grep: "(unlink|rmdir)\s*\([^)]*\\\$" --glob "**/*.php"
# Archive extraction
Grep: "(extractTo|extract)\s*\(" --glob "**/*.php"
# move_uploaded_file
Grep: "move_uploaded_file\s*\(" --glob "**/*.php"
// SECURE: Validate path is within allowed directory
final class SafeFileReader
{
public function __construct(
private readonly string $baseDir,
) {}
public function read(string $filename): string
{
$basePath = realpath($this->baseDir);
$fullPath = realpath($this->baseDir . '/' . $filename);
if ($fullPath === false) {
throw new FileNotFoundException('File not found');
}
if (!str_starts_with($fullPath, $basePath . '/')) {
throw new SecurityException('Path traversal detected');
}
return file_get_contents($fullPath);
}
}
// SECURE: Extract only filename, no path
$filename = basename($_GET['file']);
$filepath = '/uploads/' . $filename;
// SECURE: Remove path separators
$safeName = str_replace(['/', '\\', '..'], '', $_GET['file']);
// SECURE: Whitelist allowed files
final class TemplateLoader
{
private const ALLOWED_TEMPLATES = [
'header',
'footer',
'sidebar',
'content',
];
public function load(string $name): string
{
if (!in_array($name, self::ALLOWED_TEMPLATES, true)) {
throw new InvalidArgumentException('Invalid template');
}
return file_get_contents("/templates/{$name}.php");
}
}
// SECURE: Use database ID instead of filename
final class DocumentController
{
public function download(int $documentId): Response
{
$document = $this->repository->find($documentId);
if ($document === null) {
throw new NotFoundException();
}
// User can't manipulate stored path
return $this->file($document->getStoredPath());
}
}
// SECURE: Validate paths before extraction
final class SafeZipExtractor
{
public function extract(string $zipPath, string $destDir): void
{
$zip = new ZipArchive();
$zip->open($zipPath);
$destDir = realpath($destDir);
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
$targetPath = $destDir . '/' . $filename;
// Resolve path
$realTarget = realpath(dirname($targetPath));
if ($realTarget === false) {
$realTarget = $destDir;
}
// Validate within destination
if (!str_starts_with($realTarget, $destDir)) {
throw new SecurityException("Zip slip detected: {$filename}");
}
}
$zip->extractTo($destDir);
$zip->close();
}
}
// SECURE: Check if path is symlink
final class SafeFileHandler
{
public function read(string $path): string
{
if (is_link($path)) {
throw new SecurityException('Symlinks not allowed');
}
$realPath = realpath($path);
if ($realPath === false || is_link($realPath)) {
throw new SecurityException('Invalid path');
}
return file_get_contents($realPath);
}
}
// SECURE: Remove dangerous characters
final class PathSanitizer
{
public function sanitize(string $input): string
{
// Remove null bytes
$input = str_replace("\0", '', $input);
// Remove path traversal sequences
$input = str_replace(['../', '..\\', '..'], '', $input);
// Remove URL encoding
$input = urldecode($input);
$input = str_replace(['../', '..\\', '..'], '', $input);
// Only allow alphanumeric, dash, underscore, dot
if (!preg_match('/^[\w\-\.]+$/', $input)) {
throw new InvalidArgumentException('Invalid characters in path');
}
return $input;
}
}
| Pattern | Severity | CWE |
|---|---|---|
| include/require with user input | 🔴 Critical | CWE-98 |
| File read with user path | 🔴 Critical | CWE-22 |
| File write with user path | 🔴 Critical | CWE-22 |
| Zip extraction without validation | 🔴 Critical | CWE-22 |
| Upload path manipulation | 🟠 Major | CWE-22 |
| Missing realpath validation | 🟠 Major | CWE-22 |
| Symlink following | 🟡 Minor | CWE-59 |
### Path Traversal: [Description]
**Severity:** 🔴 Critical
**Location:** `file.php:line`
**CWE:** CWE-22 (Path Traversal)
**Issue:**
User input is used in file path without validation, allowing access to arbitrary files.
**Attack Vector:**
1. Input: `../../../etc/passwd`
2. Path becomes: `/uploads/../../../etc/passwd`
3. Resolves to: `/etc/passwd`
4. Attacker reads system files
**Code:**
```php
// Vulnerable
$content = file_get_contents('/uploads/' . $_GET['file']);
Fix:
// Secure: Validate path within allowed directory
$basePath = realpath('/uploads');
$fullPath = realpath('/uploads/' . $_GET['file']);
if ($fullPath === false || !str_starts_with($fullPath, $basePath . '/')) {
throw new SecurityException('Invalid path');
}
$content = file_get_contents($fullPath);
References:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub dykyi-roman/awesome-claude-code --plugin acc283 skills in this plugin
/access-control-knowledgeAccess Control knowledge base. Provides ACL, RBAC, ABAC, ReBAC models, multi-tenancy patterns, and PHP implementations (Symfony Voters, Laravel Gates) for security audits and generation./adr-knowledgeAction-Domain-Responder pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for ADR (web-specific MVC alternative) audits./adr-templateGenerates Architecture Decision Records (ADR) for PHP projects. Creates structured decision documentation with context, decision, and consequences.Other plugins' skills for the same job