Drupal Private Files: Verify Who Can Download Them

Moving an upload into Drupal’s private file system is an important boundary, but the word “private” can create a false sense of security. Drupal routes private downloads through its access handling; whether a person may download a file still depends on the content and access rules that apply to it. Test the actual URL as an anonymous visitor and as the intended user role.

Editorial illustration: a Drupal file request passes through an access checkpoint before a private document is delivered to an authorized user

Editorial illustration; roles and file access shown are conceptual.

Summary

  • Private storage keeps files outside direct public web serving, but it does not mean every download is denied.
  • Drupal may allow access when a user can view the entity containing the file; unpublished or restricted content can change the result.
  • Audit the file field, private path, entity permissions and real download URLs with test accounts.

Understand the three separate checks

Drupal distinguishes public and private file schemes. Public files are intended to be served directly by the web server. Private files are delivered through Drupal, which can apply access checks to the request. The Drupal file module documentation notes that a private file attached to published content may be downloadable by people who can view that content. Private storage alone does not make a public page’s attachment confidential.

There are therefore three questions: Is the file physically in the intended storage area? Does the web server bypass Drupal and serve it directly? Does Drupal’s route allow the current user to download it? All three matter. A configuration that answers the first correctly can still expose a file through public content or a custom route.

Audit the configuration

  1. Find the private file path. In Configuration → Media → File system, confirm a private file path is configured and points outside the public document root where your hosting setup requires it. Do not paste private server paths into public reports.
  2. Check the field destination. Edit the relevant content or media type’s file field and verify its upload destination is Private files. A single site can have both public and private fields; do not assume a content type uses the right one.
  3. Review the content’s access rules. Determine who can view the node or media entity, including unpublished content, revisions, and role-specific access. A file attached to a published page may be intentionally downloadable to everyone who can see that page.
  4. Check web-server protection. Drupal’s status report can identify file directories that are not sufficiently protected against code execution. Drupal documents .htaccess safeguards for Apache and notes that other servers need their own equivalent configuration. Do not copy Apache rules into Nginx and assume the result is protected.
  5. Inspect custom delivery. Modules can implement hook_file_download() to control access to private downloads. Custom controllers, reverse proxies and CDN rules may add another path that needs review.

Test like a visitor

Create a non-sensitive test document and attach it to representative content. Copy the generated download URL. Test it in a private browser window with no Drupal session, then as a low-privilege account and as an authorized role. Repeat after publishing, unpublishing or restricting the content if those states matter to your use case.

A successful test should confirm the intended result, not merely that the URL is obscure. A private file URL may be guessable or shared. If confidential material must only be available to a specific user or group, test that user’s permissions and verify that another account receives an access-denied response. Check both the page link and direct URL.

For media, Drupal’s documentation cautions that media items do not necessarily inherit the access rules of their parent content in the way a site owner might expect. Review the media entity’s own publication state and file field configuration. If the required rule is more granular than Drupal core provides for your model, use a maintained access-control solution or custom implementation reviewed by someone familiar with Drupal’s file APIs.

Deployment and backup checks

After moving a site or changing its file path, confirm the directory exists, is readable by Drupal, and is not exposed by the web server. Check the status report and test a real download. If configuration is deployed between environments, ensure the private path is set correctly per environment without committing server-specific secrets or local paths into shared configuration.

Include private files in backup and restore planning. A database restore without the corresponding file directory can leave broken links; a file restore into a public directory can change the exposure boundary. Rehearse both the restore and the access tests on a non-production copy.

Common mistakes

  • Treating “private://” as an automatic deny rule for every role.
  • Storing sensitive files on a published page that anonymous users can view.
  • Checking only the upload form and never testing the direct download URL.
  • Relying on .htaccess when the site runs on a server that does not use Apache.
  • Forgetting that custom media access and CDN behavior may add separate paths.

Our guides to reviewing Drupal configuration imports and sanitizing a Drupal staging database can help keep the same access assumptions across deployment and test environments.

My Take

The right question is not “Is this file private?” but “Which account can fetch this exact URL in each content state?” That small shift turns a storage setting into a testable access rule.

Bottom Line

Use the private scheme, protect the server directory, and verify the real download path with anonymous and role-based test accounts. Treat storage, entity access and delivery infrastructure as one end-to-end control.

Sources