agentleFS
ivangrynenkoivangrynenko/cursorrules/.cursor/rules/drupal-file-permissions.mdc

cursorrules / rules

Cursor rule88 starsChanged 13 months agoMITView on GitHub

Drupal file permissions security standards

The file

We split this drupal-file-permissions.mdc into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Create a script at /app/scripts/custom/fix-drupal-permissions.sh:

    line 57
  2. Distinctive:

    Never set 777 permissions on any Drupal files or directories

    line 99
  3. Distinctive:

    Use Drupal's private file system for sensitive uploads

    line 101
  4. Distinctive:

    Consider using file encryption for highly sensitive data

    line 103

≈ “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-file-permissions.mdc
---
description: Drupal file permissions security standards
globs: *.dockerfile, *.sh, docker-compose.yml, Dockerfile
---
# Drupal File Permissions Security

Standards for securing Drupal file permissions in Docker environments and production servers, ensuring proper security while maintaining functionality.

## Rule Details

- **Name:** drupal_file_permissions

- **Description:** Enforce secure file permissions for Drupal sites/default directory and critical files

## Filters
- file extension pattern: `\\.(dockerfile|sh|yml)$`
- file name: `^Dockerfile$|^docker-compose\\.yml$`
- content: `(?i)chmod|chown|drupal|settings\\.php|services\\.yml`

## Enforcement Checks
- Conditions:
  - pattern `chmod\\s+(?!755)\\d+\\s+[^\\n]*sites\\/default(?![^\\n]*files)` – sites/default directory should have 755 permissions (read-only for group/others)
  - pattern `chmod\\s+(?!444)\\d+\\s+[^\\n]*settings\\.php` – settings.php should have 444 permissions (read-only for everyone)
  - pattern `chmod\\s+(?!444)\\d+\\s+[^\\n]*services\\.yml` – services.yml should have 444 permissions (read-only for everyone)
  - pattern `chmod\\s+(?!755)\\d+\\s+[^\\n]*sites\\/default\\/files` – sites/default/files directory should have 755 permissions with proper ownership
  - pattern `chown\\s+(?!www-data:www-data)[^\\s]+\\s+[^\\n]*sites\\/default\\/files` – sites/default/files should be owned by the web server user (www-data:www-data)

## Suggestions
- Guidance:
## Drupal File Permissions Security Best Practices

### 1. Critical File Permissions
- **sites/default directory**: 755 (drwxr-xr-x)
- **settings.php**: 444 (r--r--r--)
- **services.yml**: 444 (r--r--r--)
- **settings.local.php**: 444 (r--r--r--)
- **sites/default/files**: 755 (drwxr-xr-x)
- **sites/default/files/** (contents): 644 (rw-r--r--) for files, 755 (drwxr-xr-x) for directories

### 2. Ownership Configuration
- **Web root**: application user (varies by environment)
- **sites/default/files**: web server user (www-data:www-data)

### 3. Implementation in Dockerfile
```dockerfile
# Set proper permissions for Drupal
RUN mkdir -p /app/${WEBROOT}/sites/default/files && \
    chown www-data:www-data /app/${WEBROOT}/sites/default/files && \
    chmod 755 /app/${WEBROOT}/sites/default && \
    chmod 444 /app/${WEBROOT}/sites/default/settings.php && \
    chmod 444 /app/${WEBROOT}/sites/default/services.yml && \
    find /app/${WEBROOT}/sites/default/files -type d -exec chmod 755 {} \\; && \
    find /app/${WEBROOT}/sites/default/files -type f -exec chmod 644 {} \\;
```

### 4. Permission Fix Script
Create a script at `/app/scripts/custom/fix-drupal-permissions.sh`:
```bash
#!/bin/bash

# Exit on error
set -e

WEBROOT=${WEBROOT:-web}

echo "Setting Drupal file permissions..."

# Ensure directories exist
mkdir -p /app/${WEBROOT}/sites/default/files

# Set ownership
chown www-data:www-data /app/${WEBROOT}/sites/default/files

# Set directory permissions
chmod 755 /app/${WEBROOT}/sites/default
chmod 755 /app/${WEBROOT}/sites/default/files
find /app/${WEBROOT}/sites/default/files -type d -exec chmod 755 {} \;

# Set file permissions
chmod 444 /app/${WEBROOT}/sites/default/settings.php
[ -f /app/${WEBROOT}/sites/default/services.yml ] && chmod 444 /app/${WEBROOT}/sites/default/services.yml
[ -f /app/${WEBROOT}/sites/default/settings.local.php ] && chmod 444 /app/${WEBROOT}/sites/default/settings.local.php
find /app/${WEBROOT}/sites/default/files -type f -exec chmod 644 {} \;

echo "Drupal file permissions set successfully."
```

### 5. Verify Permissions
```bash
# Check file permissions
ahoy cli "ls -la /app/${WEBROOT}/sites/default"
ahoy cli "ls -la /app/${WEBROOT}/sites/default/files"

# Check Drupal status
ahoy drush status-report | grep -i "protected"
```

### 6. Security Considerations
- Never set 777 permissions on any Drupal files or directories
- Temporary files should be stored in private file system when possible
- Use Drupal's private file system for sensitive uploads
- Implement file access controls through Drupal's permission system
- Consider using file encryption for highly sensitive data

## Metadata
- Priority: high
- Version: 1.2

 

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.