drupal-file-permissions

Security rules for Drupal file permissions in Docker environments and production servers. They check permissions and ownership for Drupal folders and files such as settings.php, services.yml, and sites/default/files.

In plain words
What is it for?
Use them when reviewing deployment scripts or server setup that changes Drupal permissions with chmod or ownership with chown.
Why use it?
They help prevent sensitive configuration files from being changed or exposed too easily, while keeping uploaded files usable by the web server. The rules also suggest expected permission values.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/abderrahimghazali/cursor-rules/drupal-file-permissions
Clone the repo
git clone --depth 1 https://github.com/abderrahimghazali/cursor-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,392 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01392
Opus 5 $0.00000 $0.00696
Sonnet 5 $0.00000 $0.00278
Haiku 4.5 $0.00000 $0.00139

Measured 2d ago against content hash ec51c9cbe22d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

drupal-file-permissions scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Asks for rootlowPrivilege escalation

A mod that escalates privileges can change anything on the machine, not only the project.

chmod 755 /app/${WEBROOT}/sites/default && \

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

.cursor/rules/drupal-file-permissions.mdc · 135 lines

How it starts

The opening of the file, as written. The whole thing — 135 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Drupal File Permissions Security

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

actions:

  • type: enforce conditions:

    • pattern: "chmod\s+(?!755)\d+\s+[^\n]*sites\/default(?![^\n]*files)" message: "sites/default directory should have 755 permissions (read-only for group/others)"

    • pattern: "chmod\s+(?!444)\d+\s+[^\n]*settings\.php" message: "settings.php should have 444 permissions (read-only for everyone)"

    • pattern: "chmod\s+(?!444)\d+\s+[^\n]*services\.yml" message: "services.yml should have 444 permissions (read-only for everyone)"

    • pattern: "chmod\s+(?!755)\d+\s+[^\n]*sites\/default\/files" message: "sites/default/files directory should have 755 permissions with proper ownership"

    • pattern: "chown\s+(?!www-data:www-data)[^\s]+\s+[^\n]*sites\/default\/files" message: "sites/default/files should be owned by the web server user (www-data:www-data)"

  • type: suggest message: |

    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

    # 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:

    #!/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

    # 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"
    

Read the full file on GitHub · 135 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 135 lines · 1,392 tokens per session scan A ec51c9cbe22d

Subscribe to this mod's changes

drupal-file-permissions is a cursor rule published in the GitHub repository abderrahimghazali/cursor-rules (2 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,392 tokens. A static security scan graded it A with 1 finding (asks for root). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.