Check 09.14 · Security and infrastructure

Protect private information with access control

Block sensitive files, directory listings, open cloud storage and access to other users' data on Apache, Nginx, Cloudflare, AWS, WordPress, Laravel or Next.js.

Priority
Critical
Difficulty
Advanced
Estimated time
2 to 6 h
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

Access control guarantees that each piece of private information is served only to the person authorized to see it. Requiring a login is not enough: the server must also publish no sensitive file (.env, .git repository, backups, logs), cloud storage must not be open, directory listings must be disabled, and a logged-in customer must not be able to read someone else's invoice by changing a number in the URL. Once this check is done, every unauthorized request receives a 401, 403 or 404, however the URL was found.

Why it matters

Broken access control tops the OWASP Top 10 ranking of web application risks, in the 2025 edition as in the 2021 edition. It requires no advanced technique: knowing or guessing a URL is enough.

And URLs get discovered. Search engine and generative engine bots explore everything that is accessible and linked somewhere; an exposed document can be indexed, cited in an answer or collected to train a model. Malicious bots constantly test well-known paths such as /.env, /.git/config, /backup.zip or /wp-content/debug.log on every domain.

What leaks most often:

  • Configuration files: .env, wp-config.php.bak, config.php~ contain database passwords and API keys.
  • Code repositories: a published .git folder lets anyone rebuild the entire source code, secrets included.
  • Backups and exports: site.zip, dump.sql, customer CSV exports left at the root.
  • Directory listings: a folder without an index page displays all its files.
  • Insecure direct object references (IDOR): /factures/1042 accessible to a customer who is not the one on invoice 1042.
  • Open cloud storage: an S3, Google Cloud Storage or Azure Blob bucket with public read access.

Neither robots.txt, nor noindex, nor a complicated URL protects this data: see protect private content with authentication (opens in a new tab), which covers setting up authentication itself.

What it improves

  • Confidentiality Customer data, secrets and internal documents can no longer be read by a third party or a bot.
  • Overall security An exposed secret is often the first step towards a full compromise of the site.
  • Compliance Protecting personal data requires effective access control. See check applicable GDPR requirements (opens in a new tab).
  • Control over what AI says A document that cannot be accessed can be neither indexed nor cited.
  • A clean index No technical files, exports or account pages in the results.
  • Rankings No direct effect.

How to check

1. Known sensitive files. Each line should show 403 or 404:

for chemin in .env .git/config .git/HEAD .svn/entries composer.json composer.lock package.json \
  backup.zip site.zip dump.sql database.sql wp-config.php.bak wp-content/debug.log \
  storage/logs/laravel.log phpinfo.php info.php .DS_Store; do
  printf "%s %s\n" "$(curl -s -o /dev/null -w '%{http_code}' "https://example.com/$chemin")" "$chemin"
done

2. Directory listings. Open a folder without an index page, for example https://example.com/wp-content/uploads/ or https://example.com/images/. An “Index of” page is a leak.

3. What is already indexed:

site:example.com (ext:sql OR ext:env OR ext:log OR ext:bak OR ext:zip)
site:example.com intitle:"index of"
site:example.com (ext:pdf OR ext:csv OR ext:xlsx) (invoice OR contract OR confidential)

4. Direct references. With two test accounts A and B, log in as A and open one of B's resources by copying its URL or identifier (invoice, order, profile, file, API call). The response must be 403 or 404.

5. Cloud storage. Without credentials, test the URL of a private object and the bucket listing:

curl -s -o /dev/null -w "%{http_code}\n" https://NOM_DU_BUCKET.s3.amazonaws.com/
curl -s -o /dev/null -w "%{http_code}\n" https://storage.googleapis.com/NOM_DU_BUCKET/

Compliant result: 403.

6. APIs. Call the endpoints that return data (/api/users, /wp-json/wp/v2/users, exports) without a token. They must return nothing private.

How to implement

Before you start

Principles to apply whatever the environment:

Principle In practice
Deny by default Every private route or file requires explicit authorization
Check on the server, object by object The server checks that the requested resource belongs to the user, not just that the user is logged in
Keep secrets out of the public folder .env, backups, logs and exports live above the web root
Serve private files through the application Controlled download or time-limited signed URL, never a permanent direct link
Least privilege Named admin accounts, minimal roles, restricted admin access
Debug mode off in production Detailed error pages expose environment variables and paths

Then remove the sensitive files already published, and change the secrets they contained: an exposed password must be considered compromised, even once the file is deleted.

Warning: blocking a file in robots.txt amounts to publishing its path. Protect it at the server level, and remove it from robots.txt.

Apache

Versions Apache 2.4.

In the virtual host or the root .htaccess:

Options -Indexes

RedirectMatch 404 "/\.(?!well-known/)"
RedirectMatch 404 "(?i)\.(sql|bak|old|orig|swp|log|ini|env|sh)$"
RedirectMatch 404 "(?i)/(composer\.(json|lock)|package(-lock)?\.json|phpinfo\.php|info\.php)$"
RedirectMatch 404 "(?i)^/(wp-content/uploads|storage|uploads)/.*\.php$"
  • Options -Indexes removes directory listings; in a .htaccess, the host must allow AllowOverride Options.
  • The first rule returns 404 for any path containing a segment that starts with a dot (.git, .env, .svn), except /.well-known/, which is needed for certificates and some verification files.
  • Add zip, gz or tar to the second rule if the site offers no archives for download.
  • The last rule prevents PHP files dropped into upload folders from being called.

Restricting the admin to fixed IP addresses, for example for WordPress:

<Files "wp-login.php">
    Require ip 203.0.113.10 198.51.100.0/24
</Files>

Test, then reload: sudo apachectl configtest && sudo systemctl reload apache2.

Nginx

Versions Nginx 1.18 and later.

In the server block, before the location ~ \.php$ block:

autoindex off;

location ~ /\.(?!well-known/) {
    return 404;
}

location ~* \.(sql|bak|old|orig|swp|log|ini|env|sh)$ {
    return 404;
}

location ~* ^/(composer\.(json|lock)|package(-lock)?\.json|phpinfo\.php|info\.php)$ {
    return 404;
}

location ~* ^/(wp-content/uploads|storage|uploads)/.*\.php$ {
    return 404;
}

Nginx applies the first regular expression that matches, in the order of the file: if location ~ \.php$ comes first, the PHP block in upload folders is ignored. To reserve the admin for specific addresses:

location = /wp-login.php {
    allow 203.0.113.10;
    deny all;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}

Reload with sudo nginx -t && sudo systemctl reload nginx.

IIS

Versions IIS 10 (Windows Server 2016 to 2025).

In the site's web.config:

<configuration>
  <system.webServer>
    <directoryBrowse enabled="false" />
    <security>
      <requestFiltering>
        <hiddenSegments>
          <add segment=".git" />
          <add segment=".env" />
          <add segment=".svn" />
        </hiddenSegments>
        <fileExtensions allowUnlisted="true">
          <add fileExtension=".sql" allowed="false" />
          <add fileExtension=".bak" allowed="false" />
          <add fileExtension=".log" allowed="false" />
        </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

IIS then returns 404 for these segments and extensions. Do not add .config: IIS already denies it by default, and declaring it a second time causes a 500.19 error (duplicate entry).

Cloudflare

Versions Cloudflare dashboard, all plans, November 2026; Cloudflare Access with the Zero Trust plan.

A firewall rule blocks sensitive paths at the edge, before they even reach the origin. In Security rules, create a custom rule with the expression:

(http.request.uri.path contains "/.git" or http.request.uri.path contains "/.env" or http.request.uri.path contains "/.svn" or http.request.uri.path.extension in {"sql" "bak" "log" "env" "old"})

Action: Block. This rule complements the origin's configuration without replacing it: direct access to the server's IP address bypasses it.

For the admin, Cloudflare Access (Zero Trust plan) puts authentication in front of a path, for example example.com/wp-admin: only authorized accounts reach the CMS login page.

AWS

Versions Amazon S3, CloudFront and IAM, console and AWS CLI v2, November 2026.

  • S3: Block Public Access is enabled by default on buckets created since April 2023. Check it on older buckets and at the account level:
aws s3api get-public-access-block --bucket NOM_DU_BUCKET
aws s3api put-public-access-block --bucket NOM_DU_BUCKET \
  --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
  • Private files: serve them through a time-limited presigned URL, generated by the application after checking permissions:
aws s3 presign s3://NOM_DU_BUCKET/factures/2026-1042.pdf --expires-in 900
  • The site's public files: serve them through CloudFront with origin access control (OAC), keeping the bucket private.
  • IAM: give the application a policy limited to the bucket and the actions it needs.

Google Cloud

Versions Cloud Storage and Google Cloud CLI (gcloud storage), November 2026.

Enable public access prevention and uniform bucket-level access:

gcloud storage buckets update gs://NOM_DU_BUCKET --public-access-prevention --uniform-bucket-level-access

For a private file, generate a time-limited signed URL from the application (client library) or from the command line with gcloud storage sign-url.

Azure

Versions Azure Blob Storage and Azure CLI 2.x, November 2026.

Disable anonymous blob access at the storage account level. It is denied by default on recent accounts: check older accounts above all. The $web container of a static website is always public.

az storage account update --name COMPTE --resource-group GROUPE --allow-blob-public-access false

Serve private files through a short-lived user delegation shared access signature (SAS), generated after checking permissions.

Plesk

Versions Plesk Obsidian 18.0.

Websites & Domains > your domain > Apache & nginx Settings: paste the Nginx blocks into “Additional nginx directives” and the Apache rules into the .htaccess. To password-protect a folder, use the domain's Password-Protected Directories. Check in the File Manager that no backup or export is lying around in httpdocs.

cPanel

Versions cPanel & WHM 130 and later, Jupiter theme.

  • Advanced > Indexes: choose “No Indexing” for the root, which disables directory listings.
  • Files > Directory Privacy: password-protects a folder.
  • Security > IP Blocker: blocks addresses or ranges.
  • The File Manager, with hidden files shown, lets you spot .env, .git and archives in public_html.

Shared hosting

Paste the block from the Apache section into the .htaccess at the root. If the account allows it, place the .env file or the configuration above public_html (most frameworks provide for this). Delete the backups and exports created by plugins in the public folder, and store them elsewhere: see automate backups and test restores (opens in a new tab).

WordPress

Versions WordPress 6.4 to 7.1.

  • User enumeration: by default, the REST API lists authors who have published (/wp-json/wp/v2/users), which gives away their login names. Hide it from logged-out visitors with a must-use plugin, wp-content/mu-plugins/restreindre-api-utilisateurs.php:
<?php

add_filter('rest_endpoints', function (array $endpoints): array {
    if (is_user_logged_in()) {
        return $endpoints;
    }

    unset($endpoints['/wp/v2/users'], $endpoints['/wp/v2/users/(?P<id>[\d]+)']);

    return $endpoints;
});
  • Debug log: wp-content/debug.log is public. In production, disable WP_DEBUG or write the log outside the public folder in wp-config.php: define('WP_DEBUG_LOG', '/var/log/wordpress/debug.log');.
  • Media: any file uploaded to the Media Library is public through its URL, even when attached to a private page. Documents reserved for customers or members must go through a plugin that serves them after checking permissions, or be stored outside uploads.
  • Roles: wp user list --role=administrator; demote accounts that do not need the administrator role, and delete those of former contractors.

Shopify

Versions Shopify admin, all plans, November 2026.

Shopify handles access control for customer accounts and orders. Two points remain your responsibility: files uploaded to Content > Files are publicly accessible through their URL, so never put a confidential document there; and staff accounts must have permissions limited to their role, in Settings > Users.

Laravel

Versions Laravel 11 to 13.

Check each object with a policy, not just authentication:

class InvoicePolicy
{
    public function view(User $user, Invoice $invoice): bool
    {
        return $invoice->user_id === $user->id;
    }
}
Route::get('/factures/{invoice}', [InvoicesController::class, 'show'])
    ->middleware('auth')
    ->can('view', 'invoice')
    ->name('invoiceShow');

Store private files on the local disk, outside public, and serve them after checking:

public function show(Invoice $invoice): StreamedResponse
{
    return Storage::disk('local')->download($invoice->path);
}

For a link sent by email, use a time-limited signed route, protected by the signed middleware:

Route::get('/factures/{invoice}/telechargement', [InvoiceDownloadsController::class, 'show'])
    ->middleware('signed')
    ->name('invoiceDownload');

$url = URL::temporarySignedRoute('invoiceDownload', now()->addMinutes(30), ['invoice' => $invoice->id]);

Any change to the URL, or an expired link, returns a 403 error.

In production, APP_DEBUG=false: the detailed error page displays environment variables. The web server must point to public/, never to the project root, otherwise .env can be downloaded.

Next.js

Versions Next.js 15 and 16 (App Router).

Do not rely on the proxy.ts file alone (middleware.ts up to Next.js 15, renamed in Next.js 16) to protect data: it serves as a first barrier and for redirects, but every data read must check the session and permissions again, in a server-side data access layer:

import 'server-only';
import { verifySession } from '@/lib/session';
import { db } from '@/lib/db';

export async function getInvoice(id: string) {
  const session = await verifySession();

  if (!session) {
    return null;
  }

  const invoice = await db.invoice.findUnique({ where: { id } });

  if (!invoice || invoice.userId !== session.userId) {
    return null;
  }

  return invoice;
}

verifySession and db stand for your own session and database access code. Apply the same check in every Server Action and every app/api route. Variables prefixed with NEXT_PUBLIC_ are included in the JavaScript sent to the browser: never put a secret in them.

Common mistakes

  • Checking the login but not ownership: any logged-in customer can read other people's data by changing an identifier.
  • Protecting the page but not the file: the linked PDF remains accessible through its direct URL.
  • Listing sensitive paths in robots.txt: it is a map for attackers.
  • Deleting an exposed .env without changing the secrets: they remain compromised.
  • Deploying with the .git folder or a backup copy in the web root.
  • Trusting a hard-to-guess identifier: URLs leak through referrers, messaging apps and logs.
  • Leaving debug mode on in production.
  • Blocking only at the CDN: direct access to the origin bypasses the rule.

Frequently asked questions

How can I tell whether my .env file or .git folder is accessible?

Request https://your-domain/.env and https://your-domain/.git/config directly with a browser or curl. A 403 or 404 response is compliant; a 200 response with content means the file is public. In that case, block access at the server level, remove the file from the public folder and immediately change every password and key it contained.

Is robots.txt enough to hide a private folder?

No. Robots.txt is an instruction that well-behaved bots choose to follow, and a public file that anyone can read. Listing a private folder in it amounts to pointing out where it is. Only a server-side check, with authentication and permission checks on each resource, actually prevents a bot, an AI assistant or a stranger from accessing the content.

What is an IDOR vulnerability and how do you avoid it?

An IDOR vulnerability, short for insecure direct object reference, lets a logged-in user access someone else's data by changing an identifier in the URL or the API, for example an invoice number. You avoid it by checking on the server, on every request, that the requested resource really belongs to the user, for example with a Laravel policy or a data access layer.

Are WordPress Media Library files private?

No. Every file uploaded to the WordPress Media Library is stored in wp-content/uploads and publicly accessible through its URL, even if it is only linked from a private or password-protected page. For documents reserved for customers or members, use a plugin that serves them after checking permissions, or store them outside the public folder.

Updated on

Topic checklist (PDF)

And now?

In the “Security and infrastructure” topic

  1. Use HTTPS everywhere
  2. Check SSL/TLS and automatic renewal
  3. Redirect HTTP to HTTPS
  4. Fix mixed content
  5. Configure security headers
  6. Configure HSTS if appropriate
  7. Update the CMS, plugins and dependencies
  8. Remove unnecessary plugins
  9. Automate backups and test restores
  10. Monitor for hacking and content or link injection
  11. Check Search Console security issues
  12. Check manual actions
  13. Monitor uptime and alerts
  14. Protect private information with access control