agentleFS
ivangrynenkoivangrynenko/cursorrules/.cursor/rules/drupal-insecure-design.mdc

cursorrules / rules

Cursor rule88 starsChanged 13 months agoMITView on GitHub

Detect and prevent insecure design patterns in Drupal as defined in OWASP Top 10:2021-A04

The file

Show its rules and text

We split this drupal-insecure-design.mdc into the rules it gives an agent

15 rules. About 0 are common, 15 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈15

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow the principle of least privilege for all user roles and permissions

    line 48
  2. Distinctive:

    Use Drupal's entity/field API for structured data instead of custom tables

    line 50
  3. Distinctive:

    Follow Drupal coding standards to leverage community security expertise

    line 52
  4. Distinctive:

    Avoid creating omnipotent permissions that grant excessive access

    line 56
  5. Distinctive:

    Use context-aware access systems like Entity Access or Node Grants

    line 57
  6. Distinctive:

    Consider record-based and field-based access for better control

    line 58
  7. Distinctive:

    Document permission architecture and security implications

    line 59
  8. Distinctive:

    Use hooks judiciously and document security implications

    line 63
  9. Distinctive:

    Use appropriate field types for sensitive data

    line 71
  10. Distinctive:

    Consider encryption for sensitive stored data

    line 73
  11. Distinctive:

    Avoid exposing sensitive data in error messages

    line 78
  12. Distinctive:

    Check 1: Proper dependency injection

    line 85
  13. Distinctive:

    Check 2: Configuration schema usage

    line 87
  14. Distinctive:

    Check 3: Proper permission definition

    line 89
  15. Distinctive:

    Check 4: Entity access handlers

    line 91

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
drupal-insecure-design.mdc
---
description: Detect and prevent insecure design patterns in Drupal as defined in OWASP Top 10:2021-A04
globs: *.php, *.install, *.module, *.inc, *.theme, *.yml, *.info
alwaysApply: false
---
# Drupal Insecure Design Security Standards (OWASP A04:2021)

This rule enforces security best practices to prevent insecure design vulnerabilities in Drupal applications, as defined in OWASP Top 10:2021-A04.

## Rule Details

- **Name:** drupal_insecure_design

- **Description:** Detect and prevent insecure design patterns in Drupal as defined in OWASP Top 10:2021-A04

## Filters
- file extension pattern: `\\.(php|inc|module|install|theme|info\\.yml)$`
- file path pattern: `(modules|themes|profiles)/custom`

## Enforcement Checks
- Conditions:
  - pattern `\\$permissions\\[['\"][^'\"]+['\"]\\]\\s*=\\s*array\\((?![^)]*(administer|manage|edit|delete)[^)]*(content|configuration|users)).*?\\);` – Permissions should follow Drupal naming patterns (verb + object) and be specific. Avoid overly broad permissions.
    - Pattern 1: Insecure permission design
  - pattern `if\\s*\\([^\\)]*===?\\s*['\"][a-zA-Z0-9_]+['\"]\\s*\\)` – Consider moving business logic rules to configuration to allow for proper adjustment without code changes.
    - Pattern 2: Hard-coded business logic values
  - pattern `preg_replace|str_replace|strip_tags` – Avoid ad hoc sanitization. Use Drupal's built-in sanitization tools: t(), Xss::filter(), etc.
    - Pattern 3: Ad hoc input sanitization
  - pattern `class\\s+[a-zA-Z0-9_]+Controller.+\\{[^}]*->query\\(` – Follow separation of concerns. Move database logic to services or repositories, not in controllers.
    - Pattern 4: Database logic in controllers
  - pattern `function\\s+[a-zA-Z0-9_]+_entity_access\\([^)]*\\)\\s*\\{[^}]*return\\s+AccessResult::allowed\\(\\);` – Avoid unconditional access grants. Implement proper conditional checks based on roles, permissions, or entity ownership.
    - Pattern 5: Weak entity access policy
  - pattern `session_start|session_set_cookie_params` – Avoid custom session management. Use Drupal's session handling system and services.
    - Pattern 6: Custom session management
  - pattern `(?:\\\\Drupal::[a-zA-Z_]+\\(\\).*){3,}` – Excessive static service calls indicate poor dependency injection. Use proper service injection.
    - Pattern 7: Excessive global state dependency
  - pattern `password_verify\\(|password_hash\\(` – Avoid custom authentication. Use Drupal's built-in authentication system and services.
    - Pattern 8: Custom user authentication
  - pattern `function\\s+[a-zA-Z0-9_]+_schema\\(\\)[^{]*\\{[^}]*return\\s+\\$schema;(?![^}]*validate_utf8|[^}]*'not null')` – Database schemas should enforce data integrity with proper constraints (NOT NULL, length, etc.).
    - Pattern 9: Missing schema definitions
  - pattern `\\$config\\[['\"](mdc:?!secure_|security_|private_)[^'\"]+['\"]\\]\\s*=\\s*(?:FALSE|0|'0'|\"0\");` – Security-related configuration should default to secure settings (opt-in for potentially insecure features).
    - Pattern 10: Insecure defaults

## Suggestions
- Guidance:
**Drupal Secure Design Best Practices:**

1. **Secure Architecture Principles:**
   - Follow the principle of least privilege for all user roles and permissions
   - Implement defense in depth with multiple security layers
   - Use Drupal's entity/field API for structured data instead of custom tables
   - Employ service-oriented architecture with proper dependency injection
   - Follow Drupal coding standards to leverage community security expertise

2. **Permission System Design:**
   - Design granular permissions following the verb+object pattern
   - Avoid creating omnipotent permissions that grant excessive access
   - Use context-aware access systems like Entity Access or Node Grants
   - Consider record-based and field-based access for better control
   - Document permission architecture and security implications

3. **Module Architecture:**
   - Separate concerns into appropriate services
   - Use hooks judiciously and document security implications
   - Implement proper validation and sanitization layers
   - Design APIs with security in mind from the start
   - Provide secure default configurations

4. **Data Modeling Security:**
   - Implement appropriate validation constraints on entity fields
   - Design schema definitions with integrity constraints
   - Use appropriate field types for sensitive data
   - Implement field-level access control when needed
   - Consider encryption for sensitive stored data

5. **Error Handling and Logging:**
   - Design contextual error messages (detailed for admins, general for users)
   - Implement appropriate logging for security events
   - Avoid exposing sensitive data in error messages
   - Design fault-tolerant systems that fail securely
   - Include appropriate transaction management

## Validation Checks
- Conditions:
  - pattern `protected\\s+\\$[a-zA-Z0-9_]+;[^}]*public\\s+function\\s+__construct\\([^\\)]*\\)` – Using proper dependency injection pattern.
    - Check 1: Proper dependency injection
  - pattern `config\\/schema\\/[a-zA-Z0-9_]+\\.schema\\.yml` – Providing configuration schema for validation.
    - Check 2: Configuration schema usage
  - pattern `\\$permissions\\[['\"][a-z\\s]+[a-z0-9\\s]+['\"]\\]\\s*=\\s*\\[` – Following permission naming conventions.
    - Check 3: Proper permission definition
  - pattern `@EntityAccessControl\\(|class\\s+[a-zA-Z0-9_]+AccessControlHandler\\s+extends\\s+` – Using dedicated access control handlers for entities.
    - Check 4: Entity access handlers

## Metadata
- Priority: high
- Version: 1.1
- Tags: security, drupal, design, architecture, owasp, language:php, framework:drupal, category:security, subcategory:design, standard:owasp-top10, risk:a04-insecure-design
## References
- https://owasp.org/Top10/A04_2021-Insecure_Design/
- https://www.drupal.org/docs/develop/security-in-drupal
- https://www.drupal.org/docs/8/api/entity-api/access-control-for-entities
- https://www.drupal.org/docs/8/api/configuration-api/configuration-schemametadata

 

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.