siva01c avatar

drupal-dev-tools

Drupal 11 toolkit — audit command and skills for module development and security review

version
4.1.0
GitHub stars
16

Install

/plugin install drupal-dev-tools@dev-tools

Run it inside Claude Code after adding the marketplace with /plugin marketplace add siva01c/claude-plugins.

Contents

Discovered from source

Skills 2

Drupal Module Development Skill

Purpose

Use this skill when creating or extending custom Drupal 11 modules with modern architecture and maintainable code.

When to apply

  • Building a new custom module in web/modules/custom.
  • Adding services, event subscribers, forms, or controllers.
  • Refactoring procedural logic to service-based design.

Workflow

  1. Scaffold the module structure (.info.yml, .services.yml, routing, permissions).
  2. Register dependencies through service definitions and constructor injection.
  3. Build controllers/forms/plugins using Drupal 11 APIs and strict typing.
  4. Add config schema for any custom configuration.
  5. Validate with Drush cache rebuild and config export.

Guardrails

  • Avoid direct use of superglobals in business logic.
  • Prefer dependency injection over static service locators.
  • Keep schema, permissions, routes, and services documented and versioned.
  • Do not modify Drupal core or contrib module code directly.

Quick command checklist

drush en <module_name> -y
drush cr
drush config:export -y

In a containerized environment, prefix with your runner (e.g. ddev drush … — see the ddev-tools plugin).

Drupal Security Review Skill

Purpose

Use this skill to perform focused security reviews for Drupal 11 custom modules and themes.

When to apply

  • Reviewing pull requests before merge.
  • Auditing custom code for common web vulnerabilities.
  • Preparing release readiness checks.

Review checklist

  1. Input handling: Validate and sanitize all external input.
  2. Output escaping: Escape output in Twig and PHP render logic.
  3. Database safety: Use query builder or placeholders in all SQL operations.
  4. Access control: Confirm route, entity, and operation permissions are enforced.
  5. Secrets and config: Ensure credentials are never committed and sensitive config is protected.

Common anti-patterns to flag

  • Direct SQL string concatenation with user data.
  • Unescaped raw markup in render arrays.
  • Trusting $_GET, $_POST, or request payloads without validation.
  • Debug leftovers (var_dump, kint, dpm) in production paths.

Useful validation commands

rg "(var_dump|dpm\(|kint\()" web/modules/custom web/themes/custom
rg "\$_(GET|POST|REQUEST)" web/modules/custom web/themes/custom

For a deterministic scan with triage and ASVS mapping, use the security-tools:semgrep skill (Semgrep with custom Drupal rules) before the checklist above and review its findings first.

Commands 1

System: You are an expert Drupal 11 code auditor and security analyst. You follow Drupal.org coding standards, the Drupal 11 API, and PHP 8.3 best practices. You provide detailed, structured, and actionable feedback with references to Drupal documentation where relevant.


User: Analyze this Drupal project.


Task: Perform a full audit of all custom themes and modules in the project. Provide a structured report based on the following areas:

1. Drupal 11 Best Practices

  • Verify the project follows Drupal 11 coding standards and conventions.
  • Check for use of modern APIs (services, render arrays, configuration management).
  • Ensure no deprecated or legacy procedural code is used.

2. Code Quality and Design

  • Identify violations of SOLID and DRY principles.
  • Detect incorrect or unnecessary dependency injection.
  • Review the use of design patterns and suggest improvements where patterns such as Factory, Strategy, or Observer would fit better.

3. Security Review

  • Search for vulnerabilities, including:

    • SQL injection (e.g., direct queries without placeholders)
    • XSS risks (missing Html::escape(), t(), Xss::filter())
    • Unsafe use of $_GET, $_POST, or $_REQUEST
  • Check for proper input sanitization and output escaping.

  • Identify abandoned debug functions (e.g., var_dump(), dpm(), kint(), watchdog() used incorrectly).

  • Optional SAST step: if the security-tools:semgrep skill is installed and Semgrep can run (local semgrep or docker run semgrep/semgrep), scan the custom modules and themes with it first and use its findings as the starting point of this section. Triage every finding (true positive / false positive / needs context) and report it with rule id, file:line and the OWASP ASVS requirement. If Semgrep cannot run, say so in the report and continue with the manual review.

4. Code Duplication

  • Find and report duplicated functions, repeated logic, or redundant service implementations.

5. Report Output

Provide a structured analysis with the following sections:

  • Compliance with Drupal 11 standards
  • Found vulnerabilities and security risks (Semgrep findings with their triage verdict, when the scan ran)
  • Design and dependency injection issues
  • Code duplication summary
  • Recommendations for refactoring

Reference Examples of Best Practice Code:

// Safe client-side escaping
var rawInputText = $('#form-input').text();
var escapedInputText = Drupal.checkPlain(rawInputText);
// Safe query with parameter binding
\Drupal::database()->query(
  'SELECT foo FROM {table} t WHERE t.name = :name',
  [':name' => $name]
);

// Safe query using Drupal's query builder
$users = ['joe', 'poe', $name];
$result = \Drupal::database()
  ->select('foo', 'f')
  ->fields('f', ['bar'])
  ->condition('f.bar', $users)
  ->execute();

// Proper LIKE condition with escapeLike()
$conn = \Drupal::database();
$conn->select('table', 't')
  ->condition('t.field', '%_' . $conn->escapeLike($name), 'LIKE')
  ->execute();

// Safe CSS class sanitization
public function elementClasses($row_index = NULL) {
  $classes = $this->tokenizeValue($this->options['element_class'], $row_index);
  $classes = explode(' ', $classes);
  foreach ($classes as &$class) {
    $class = Html::cleanCssIdentifier($class);
  }
  return implode(' ', $classes);
}

Sponsors

Details

Marketplace
siva01c/claude-plugins
Source
drupal-dev-tools
Author
Ludek Kvapil - siva01
Category
Community

More from siva01c/claude-plugins

All 8