Medifence – Access Control for Media Uploads
Blocks direct access to uploaded media files for visitors who are not logged in.
Install in
By default, every file inside the WordPress uploads directory can be opened by anyone who knows its URL. For membership sites this means that protected content pages are useless if the images inside them can still be opened directly.
Medifence puts a login check in front of every uploads request — without changing a single URL and without moving any files.
How it works
On activation, the plugin writes a small rule block into the .htaccess file inside your uploads directory (using WordPress’s own marker mechanism, so rules from other plugins are preserved). Requests for existing files are rewritten to WordPress itself, which bootstraps normally; the plugin then verifies the visitor is logged in and streams the file. No WordPress core file is ever loaded directly. Deactivating or uninstalling the plugin removes the rules, and your files are served normally again.
Features
- File URLs stay exactly the same — nothing to update in posts or the database
- Physical files stay where they are — no migration needed
- Built-in live verification: the settings screen requests a test file without a session cookie and shows the actual HTTP status anonymous visitors receive
- A warning appears on all admin screens if another plugin overwrites the rules
- Optionally require a specific capability in addition to being logged in
- Or give individual folders their own capability, so one membership tier cannot reach another’s files
- Choose the denied status code (403, 404, or 401) — 404 hides that the file exists
- Or send visitors who open a protected file to the login screen, and back to the file afterwards
- Or to a page of your own — a membership or contact page, for people who have no account yet
- Either way they are told which file they were opening, so the redirect does not read as a broken site
- Optionally serve a placeholder image instead of denied images — your own, or the grey padlock included with the plugin
- Exclude specific file extensions (useful when your theme loads CSS or fonts from uploads)
- Excluding a document or archive type — pdf, zip, docx — is flagged before and after saving, so it never happens unnoticed
- Exclude individual folders, or flip it around and protect only the folders you list — picked from the folders you actually have
- Or let each file follow the post it is attached to: published posts stay public, private ones require a login
- Publish the generated image sizes a gallery needs while the full-resolution original stays protected
- WebP and AVIF copies made by an image optimizer follow the file they were made from — published size or protected original
- Make a single file an exception to all of that — always public, or always protected — from the media library
- Narrow the media library list to one protection state, to select what is exposed and fix it without leaving the screen
- A shortcode lists the files of a folder that the current visitor may download — the member page that never drifts out of date
- Share a single protected file with someone who has no account, using an expiring signed link — and revoke any of them individually
- Limit a share link to a number of downloads, note down who it was issued to, and see how often it has been used
- Give a share link a password as a second factor — only its hash is stored, and guessing is cut off after 20 wrong attempts
- Or select a set of files in the media library and get all their links in one go
- Set the lifetime and download limit the share forms start with, for sites that issue many links the same way
- Send a freshly issued link by email straight from the result box — no pasting, no misaddressing
- Or a whole set at once, as one message listing every link with its file name and expiry
- Start a link from a file’s own edit screen, with the file already selected
- Download the ledger of active links as CSV — without the links themselves, so a leaked ledger leaks no access
- Search that list by file name or note, or show only what expires within a day, and page through it
- Pause the protection for a few minutes while diagnosing a problem — it always resumes by itself, and the rules stay in place
- A daily check restores the rules automatically if another plugin removes or overwrites them
- What was overwritten is kept for you to inspect — the clue to which plugin keeps doing it
- Repeated overwrites are called out as a standing conflict, instead of being silently repaired forever
- Optionally emails you when the protection stops working — once, when the verdict changes
- And when the number of files anyone can open grows, which a working set of rules will never tell you
- That number is kept as a 30-day trend, so a scope drifting wider over weeks is visible at a glance
- The files that became reachable since the previous count are named, not just counted
- Or get one summary a week — reachable files, blocked requests, active links, settings changes — even when nothing happened
- Reports the protection status in Site Health, and offers WP-CLI commands for deployments
- A dashboard widget puts the vital signs on the admin home, seen without anyone going looking
- Warns when WP-Cron is not running — the silent way every scheduled check, alert, and summary stops
- Inspect any single file to see whether it is reachable, and which setting decided it
- Preview a settings change before saving it: see exactly which files would stop being protected
- Carry a configuration from staging to production as a JSON file, reviewed before it is applied
- See which administrator changed the protection, when, and from what to what — and undo a recorded change with one click
- Audit the whole library in one click and get the list of files your settings leave public — and close them from that same list
- Download that list as CSV, from the admin screen — the evidence a compliance process asks for
- Scan the uploads directory itself for files no attachment points at — the ones nothing else reports
- Scan published content for embedded protected files — the setting that shows up as a broken image on a public page
- Or be told at once: publishing a post checks that post and names the files its visitors will not be able to open
- The audit also names the attachments whose file is missing on disk, before someone issues a share link that cannot work
- Optionally count what was blocked, per file — without storing IP addresses or user agents — and download the list as CSV
- Including the share links that were refused, and the wrong passwords: why “the link you sent does not open”
- Choose how many files the log keeps and for how long, and see the last 7 days as one count per day
- See at a glance which files are protected, from a column in the media library
- The same verdict appears in the file dialog while inserting media into a post, and as a read-only REST field for administrators
- Choose whether allowed files open in the browser or always arrive as a download — video and audio keep playing either way
- Range request support for video and audio seeking, ETag-based browser caching for logged-in users
- Lock the configuration with a wp-config.php constant, for sites where the protection scope is agreed rather than casual
- Cleans up completely on uninstall
Requirements
- Apache or LiteSpeed with mod_rewrite enabled
- A writable
.htaccessfile in the uploads directory
This plugin does not work on nginx, because nginx does not read .htaccess files. The built-in live test will tell you immediately whether your server is compatible.
For developers
The final access decision can be filtered:
add_filter( 'medifence_allow_access', function ( $allowed, $file_path ) {
// Example: always allow files inside uploads/public/.
if ( false !== strpos( $file_path, '/uploads/public/' ) ) {
return true;
}
return $allowed;
}, 10, 2 );
The WP-CLI commands, the diagnostic header, the [medifence_files] shortcode, the REST field, and the delivery details are described in the developer documentation.
Written by Joobi from the project's own listing. See the source page
1.77.1
- Security: the signing key for share links is created only once, even when the first requests that need it arrive at the same moment. Each of them used to create and save its own key, and the later one replaced the earlier — so a link issued in that moment could stop working without anyone revoking it. The key is now stored only while there is none, and every request uses the one that was stored first.
- Security: a request that merely carries a share link token no longer makes the site create its signing key; without a key no link can be valid, so the request is refused without writing anything. A stored key that is not a string of at least 32 characters is no longer used for signing and is replaced. Existing keys and links are unchanged.
1.77.0
- Security: requests that arrive at the same moment can no longer get around a share link’s limits. The list of links was read, changed and saved back by every download and every wrong password, so two overlapping requests both started from the same copy and the later save undid the earlier one. Wrong passwords sent in parallel then counted as one, so the limit of 20 attempts no longer bounded a guessing attack; parallel requests for a link’s last download could all receive the file; and a download that was under way while the link was revoked could write the revoked link back. Every change to the list is now made against the stored copy and saved only if no other request saved first — otherwise it is worked out again. A password attempt is counted before the password is checked and given back when it was right, and a download is only counted while the link still has one left.
- Issuing, revoking and deleting links, and the daily clean-up, go through the same path, so a link issued or revoked while someone is downloading is never lost or brought back. Nothing changes in what is stored or in how links behave one request at a time.
1.76.0
- Security: a share link’s download limit can no longer be bypassed with a Range or If-None-Match header. Those requests were never counted, so that a video seek or a cache check would not spend a link, which also let any client that always sent one download a “valid for one download” link as often as it liked. Now the first request a browser makes for a link is counted whatever it carries, and only the ranges and revalidations that follow it from the same browser within an hour are free. That browser is recognised by a short-lived signed cookie (
medifence_view_…, HttpOnly, never outliving the link) holding no information about the visitor. A client that keeps no cookies has every request counted. - Security: the file inspector,
wp medifence inspect, the media list, the REST field and the audits now report the files the delivery handler refuses — .htaccess and other dot files, PHP source, and files in a folder whose own .htaccess denies all access — as “Blocked for everyone”, with the new reasonsrefused_hidden,refused_scriptandrefused_closed(for a closed folder, the folder that closes it is the matched value). They used to be judged by the protection scope, so such a file read “Protected: it is inside the protected scope”, or even “Served to everyone” when it lay outside the protected paths. The uploads scan no longer lists them as public, and the embedded-file scan counts them as blocked. Files that are not refused are reported exactly as before. - Fixed: a request for the end of a file (
Range: bytes=-500) now receives the last 500 bytes; it used to receive the first 501. A Range header with several ranges, another unit, or a last byte before the first is now ignored and the whole file is sent, as RFC 9110 requires, instead of answering with only the first range or with 416. - Fixed: a resumed download whose
If-Rangeno longer matches the file — the file was replaced in between — now receives the whole file instead of a part that would be stitched onto the old copy. - Security: the CSV exports (audit, access log, share links) also escape values that begin with a tab or a carriage return, which some spreadsheets strip before reading a formula. The CSV escape character is now passed explicitly, so PHP 8.4 raises no deprecation notice; the output is unchanged.
1.75.0
- Security: the delivery handler no longer hands out files the web server itself keeps closed. Because the address it answers on can be typed by anyone, a logged-in account of any role — or anyone at all during a pause or for a folder outside the protected scope — could read .htaccess files, PHP source, and files that other plugins keep in the uploads directory behind a “deny from all” rule, such as logs, exports and backups. Those are now refused with a plain 404, the same answer as for a file that does not exist.
- Security: the check that a requested file lies inside the uploads directory now compares whole folder names, so a symbolic link that resolves to a sibling folder with the same beginning (uploads-old next to uploads) is no longer accepted.
- Security: the file name sent with a delivered file is reduced to plain ASCII, and the exact name, when it differs, travels in the RFC 6266 form, so a quote in a file name can no longer be read as part of the header.
- The [medifence_files] list and the file name shown on the login screen skip the files that are refused.
1.74.0
- One batch of the library audit is now measured in time rather than in files: about five seconds, or a thousand attachments, whichever comes first. A slow host covers fewer per press and a fast one covers more, and neither is asked for something it cannot finish.
- Each batch says how many it managed and whether it stopped on the clock or on the count, so a small number is legible as a busy server rather than as a scan that gave up.
1.73.0
- The scan of the uploads directory no longer reads every recorded attachment path into memory first, so its cost no longer grows with the size of the library. On a large site this is the difference between a scan that finishes and one the server kills.
- The directory is walked in batches instead of being listed in full, so
wp medifence stray --limit=0works on a directory of any size. - The result is unchanged: the same files are reported, for the same reasons.
1.72.0
- Every list that can be empty now says what the emptiness means — nothing done yet, or done and found nothing — instead of showing a blank space that reads as a fault.
- The 30-day trend and the last 7 days of the access log no longer disappear when there is nothing in them; they explain why they are empty and what would fill them.
- The two extra audit scans say they have not been run, so an unrun scan can no longer be mistaken for a clean result.
1.71.0
- A freshly issued share link now has a Copy button beside it, and a set issued together has one that takes every link at once.
- Where the browser refuses clipboard access — it needs a secure connection — the link is selected instead and the button says so.
1.70.0
- The path list the selected protection scope does not read is dimmed and cannot be typed into, so it is visible which of the two is deciding. Its contents are kept and apply again when the scope is switched back.
- The example text in the empty folder rule row no longer looks like a filled-in value.
1.69.0
- The verdict on where your media is served from is kept for an hour instead of being worked out again every time the status tab or Site Health is opened.
- Saving the settings or rewriting the rules drops it, so a change is still noticed at once.
1.68.0
- Looking at a screen no longer writes to the database. Reading the list of share links used to delete the expired ones as a side effect, which made the dashboard, the status summary, and the weekly mail all write on a plain visit.
- Expired links are still left out of every list and refused at delivery from the moment they expire; their records are now removed by the daily check instead.
1.67.0
- The uploads .htaccess is read once per request instead of once per question. Every admin screen asks whether the rules are still installed, and the dashboard asked three times over.
- The file is re-read as soon as the plugin writes to it, so a repair still reports what it just did.
1.66.0
- The access log now writes once per recorded request instead of twice. A page of protected images is one blocked request per image, and the record of it cost more than the record is worth.
- The per-day counts moved into the log itself. Counts written by an earlier version are taken over on the first write, so nothing already counted is lost.
1.65.0
- Resolving a file to its attachment now takes a single database query instead of up to fifteen. It runs on delivery, once per protected image on the page, so the saving is largest exactly where the load is.
- Which attachment a file belongs to is decided exactly as before, including the WebP and AVIF copies an optimizer leaves beside the originals — an ambiguous one still resolves to nothing and stays protected.
1.64.0
- The status tab now opens with a summary: whether the protection works, how many files anyone can open, what the last two scans found, and how many share links expire within a day.
- Until now those answers were spread over three tabs, and the ones behind a scan were invisible until you ran it. The summary reads stored values only — opening the tab starts no scan and no request.
- A line that has never been counted or scanned says so, rather than showing a zero.
1.63.1
- Screenshots retaken on the current screens. The previous set was from 1.53.1 and did not show the delivery setting, the audit’s CSV download, or the filter over the share links.
- Their captions were updated to match. No change to the plugin itself.
1.63.0
- New setting: whether an allowed file opens in the browser or always arrives as a download. Until now the file type decided alone, and a site that wants its PDFs saved rather than read in a tab had no say.
- Share links follow the same setting, so a file behaves the same however the visitor was allowed in.
- Video and audio keep opening in place under either choice: a download is not something a player on your page can play, so including them would break embedded media rather than change a preference.
- Files with an excluded extension or in an excluded folder are handed out by the web server and never reach the plugin, so the setting has no say over them. The screen says so.
1.62.0
- The media library list can now be narrowed to the files that are protected, or to the files anyone can open, with a dropdown next to the date filter — the short way to select what is exposed and fix it with one bulk action.
- The verdict is worked out per file and stored nowhere, so it cannot be part of the database query: the dropdown narrows the page you are looking at, not the library. The screen says so, because an almost empty page is not an answer about the library.
- Page numbers and the total keep counting every file. To go through the whole library, the Audit tab is still the tool.
1.61.0
- The list of active share links can now be narrowed: search a file name or a note, or show only the links expiring within a day, down to their last download, or carrying a password.
- Lists longer than 50 links are split into pages. A site that issues links continuously had no way to find one except by scrolling.
- The filter reads the records already loaded — no new query, and nothing is stored. The CSV export still covers every active link whatever the list is filtered to: a ledger of a filtered view would not be a ledger.
1.60.0
- The plugin now ships a placeholder image of its own — a grey padlock — for sites that just want denied images to look deliberate without preparing one first.
- Tick “Use the built-in image when no attachment is chosen” under the placeholder setting. Off by default, so nothing changes for anyone who has not asked for it.
- It also stands in when a chosen placeholder attachment has been deleted since. Until now that quietly turned the placeholder off and denied images went back to being errors.
- The image carries no text, so it reads the same in every language, and it is a plain file in the plugin — not generated at runtime.
1.59.0
- The audit’s list of files anyone can open can now be downloaded as CSV from the Audit tab: the file, the attachment, the deciding setting, and the explanation in words.
- The access log and the share link ledger have offered this for versions; the audit — the list a compliance process actually asks for — was available on the command line only.
- The file holds exactly what is on screen and never runs a fresh scan, so it cannot disagree with the list it came from. While a large library is still being worked through in batches, the screen says so next to the button rather than letting the file imply completeness.
1.58.0
- The access log now counts share links that were presented and refused — expired, revoked, or used up — and wrong passwords, each on its own.
- “I sent them a link and they say it does not open” has exactly those two answers, and until now the log could not tell them apart: a refused link disappeared into the general blocked count, and a wrong password was recorded nowhere at all.
- The new counts are added as two new columns at the end of the CSV, so anything built on an earlier export keeps working. A refused link is counted twice on purpose: once as the link that failed, once as the response the visitor received.
- Still nothing identifying is stored — no IP addresses, no user agents, no names.
1.57.0
- A set of share links issued together can now be emailed from the result box as well — one message listing every link with its file name and expiry, not one message per file.
- If any link in the set has been revoked in the meantime, nothing is sent. A message that quietly drops half of what it promises is worse than an error.
- A share link can now also be started from a file’s own edit screen, under “Medifence share link”: it opens the share form with that file already selected.
1.56.0
- A visitor sent to the login screen is now told which file they were opening, above the form. A login form appearing out of nowhere reads as a broken site rather than as a closed door.
- The name is read from the redirect the browser already carries, so nothing is added to the URL, and whatever else asks to be on that screen stays where it was.
- For the “page of your own” option, the new
[medifence_requested_file]shortcode prints the same name — so the page can say “You tried to open report.pdf” without writing any PHP. - Only the file name is ever shown, never the folder it sits in, and only for a file that exists in this site’s uploads directory: the address it comes from is one anyone can type.
1.55.0
- Publishing a post now checks that post for media its visitors cannot open, and names the files in a notice with a link back to the post.
- The published-content scan on the Audit tab answers the same question, but only for whoever thinks to run it — while a broken image is visible from the moment the post goes live. This is the same verdict, delivered to the person who wrote the post.
- Nothing is blocked and nothing is changed: the post is saved either way, and a post whose files are all reachable says nothing at all. The block editor saves in the background, so the notice appears on the next admin screen.
- Up to 30 media links per post are examined; a post with more says so rather than implying it was fully checked.
1.54.0
- Media served from another host — an offload plugin, or a CDN pointed at the uploads directory — is now named on the status tab and in Site Health as what it is: files this plugin is never asked about.
- This was the one failure that looked like success. The rules are in place, the live test requests a file from this site and passes, the audit calls the library protected — while the files themselves are handed out by somewhere else entirely.
- Judged from the media URLs alone: no HTTP request, no scan, and no list of plugin names to go out of date. The new
medifence_external_mediafilter corrects the verdict for a setup where the files do pass through this site after all.
Older versions (1.53.1 and earlier) are listed on the Medifence changelog, one post per release.
Follow this listing's changes (Atom feed)