agentleFS
ivangrynenkoivangrynenko/cursorrules/.cursor/rules/drupal-cryptographic-failures.mdc

cursorrules / rules

Cursor rule88 starsChanged 13 months agoMITView on GitHub

Detect and prevent cryptographic failures in Drupal as defined in OWASP Top 10:2021-A02

The file

Show its rules and text

We split this drupal-cryptographic-failures.mdc into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    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:

    Use Drupal's Key module for storing encryption keys

    line 48
  2. Distinctive:

    Use Drupal's State API for non-configuration sensitive data

    line 50
  3. Distinctive:

    Never store plaintext sensitive information in the database

    line 51
  4. Distinctive:

    Use Drupal's password hashing system, which uses password_hash() internally

    line 54
  5. Distinctive:

    Use the Encrypt module or PHP's openssl_encrypt() with proper algorithms (AES-256-GCM)

    line 56
  6. Distinctive:

    Always use proper salting techniques

    line 57
  7. Distinctive:

    Use secure cookies (secure, HttpOnly, SameSite)

    line 61
  8. Distinctive:

    Use TLS 1.2+ for all connections

    line 63
  9. Distinctive:

    Use OAuth or JWT with proper signature verification

    line 66
  10. Distinctive:

    Use HMAC for API request signatures when appropriate

    line 68
  11. Distinctive:

    Never expose internal encryption keys through APIs

    line 69
  12. Distinctive:

    Check 1: Proper password handling

    line 80
  13. Distinctive:

    Check 2: Proper random generation

    line 82
  14. Distinctive:

    Check 4: Proper encryption usage

    line 86

≈ “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-cryptographic-failures.mdc
---
description: Detect and prevent cryptographic failures in Drupal as defined in OWASP Top 10:2021-A02
globs: *.php, *.install, *.module, *.inc, *.theme
alwaysApply: false
---
# Drupal Cryptographic Failures Security Standards (OWASP A02:2021)

This rule enforces security best practices to prevent cryptographic failures in Drupal applications, as defined in OWASP Top 10:2021-A02.

## Rule Details

- **Name:** drupal_cryptographic_failures

- **Description:** Detect and prevent cryptographic failures in Drupal as defined in OWASP Top 10:2021-A02

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

## Enforcement Checks
- Conditions:
  - pattern `(md5|sha1)\\([^)]*\\)` – Weak hash algorithm detected. Use password_hash() for passwords or hash('sha256'/'sha512') for other data.
    - Pattern 1: Use of weak hash algorithms
  - pattern `(password|key|token|secret|credentials|pwd)\\s*=\\s*['\"][^'\"]+['\"]` – Hardcoded credentials or sensitive keys detected. Use Drupal's State API, key module, or environment variables.
    - Pattern 2: Hardcoded credentials or keys
  - pattern `\\$user->setPassword\\((?!password_hash|\\$hash)[^)]+\\)` – Never store plaintext passwords. Drupal handles password hashing internally.
    - Pattern 3: Plaintext password storage
  - pattern `file_(get|put)_contents\\([^,]+,\\s*[^,]+\\)` – Consider encrypting sensitive file contents using Drupal's encryption API or PHP's openssl functions.
    - Pattern 4: Improper file encryption
  - pattern `\\$settings\\[['\"](mdc:?!hash_salt|update_free_access)[^]]+\\]\\s*=\\s*['\"][^\"']+['\"]` – Sensitive data in settings.php should be moved to environment variables or settings.local.php.
    - Pattern 5: Unprotected sensitive data in settings
  - pattern `(rand|mt_rand|array_rand)\\(` – Insecure random number generation. Use random_bytes() or random_int() for cryptographic purposes.
    - Pattern 6: Insecure random number generation
  - pattern `'#cache'|'cache'` – Ensure HTTPS is enforced for cached pages containing sensitive information.
    - Pattern 7: Missing HTTPS enforcement
  - pattern `(->set|->get)\\('field_[^']*(?:password|ssn|credit|card|secret|key|token|credentials|pwd)[^']*'\\)` – Consider using field encryption for sensitive data fields.
    - Pattern 8: Missing encryption for content with private information
  - pattern `session_(start|regenerate_id)` – Avoid custom session handling. Use Drupal's session management services.
    - Pattern 9: Custom session handling without proper security
  - pattern `\\$token\\s*=\\s*.*?\\$[^;]+;(?![^;]*expir|[^;]*valid)` – API tokens should include expiration time or rotation mechanism.
    - Pattern 10: API tokens without expiration or rotation

## Suggestions
- Guidance:
**Drupal Cryptographic Security Best Practices:**

1. **Secure Data Storage:**
   - Use Drupal's Key module for storing encryption keys
   - Store sensitive configuration in environment variables or settings.local.php
   - Use Drupal's State API for non-configuration sensitive data
   - Never store plaintext sensitive information in the database

2. **Encryption and Hashing:**
   - Use Drupal's password hashing system, which uses password_hash() internally
   - For non-password data hashing, use SHA-256 or SHA-512
   - Use the Encrypt module or PHP's openssl_encrypt() with proper algorithms (AES-256-GCM)
   - Always use proper salting techniques

3. **Communication Security:**
   - Enforce HTTPS site-wide using settings.php configuration
   - Use secure cookies (secure, HttpOnly, SameSite)
   - Implement proper Content-Security-Policy headers
   - Use TLS 1.2+ for all connections

4. **API Security:**
   - Use OAuth or JWT with proper signature verification
   - Implement token expiration and rotation
   - Use HMAC for API request signatures when appropriate
   - Never expose internal encryption keys through APIs

5. **Configuration Best Practices:**
   - Regularly rotate encryption keys and credentials
   - Implement secure key storage using key management services
   - Monitor and log cryptographic operations 
   - Maintain an inventory of cryptographic algorithms in use

## Validation Checks
- Conditions:
  - pattern `UserInterface::PASSWORD_|password_hash\\(` – Using Drupal's password system correctly.
    - Check 1: Proper password handling
  - pattern `random_bytes|random_int|\\\\Drupal::service\\('random'\\)` – Using secure random generation methods.
    - Check 2: Proper random generation
  - pattern `getenv\\('|\\$_ENV\\['|\\$_SERVER\\['|settings\\.local\\.php` – Using environment variables or local settings correctly.
    - Check 3: Secure settings
  - pattern `openssl_encrypt\\(|\\\\Drupal::service\\('encryption'\\)` – Using proper encryption methods.
    - Check 4: Proper encryption usage

## Metadata
- Priority: high
- Version: 1.1
- Tags: security, drupal, cryptography, encryption, owasp, language:php, framework:drupal, category:security, subcategory:cryptography, standard:owasp-top10, risk:a02-cryptographic-failures
## References
- https://owasp.org/Top10/A02_2021-Cryptographic_Failures/
- https://www.drupal.org/docs/security-in-drupal
- https://www.drupal.org/project/key
- https://www.drupal.org/project/encrypt

 

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.