Skip to content

Prescription File Access

From version 1.6.0, SpecCart no longer serves prescription files directly from wp-content/uploads/speccart-prescriptions/. All file reads route through an authenticated REST endpoint:

GET /wp-json/speccart/v1/prescriptions/{attachment_id}/file

The endpoint returns the file bytes only when the caller is authorised; otherwise it returns 403 Forbidden.

There are three ways to get a 200 response from the endpoint.

CallerHow access is granted
StaffLogged-in user with the WooCommerce edit_shop_orders capability. No token is required. Used by the admin order meta box and the prescription management screen.
Customer (same session)A short-lived HMAC-signed token, issued by the server for one specific attachment with a 1-hour TTL. Used by the customer’s own wizard after a Smart Upload.
Secure-upload visitorA magic-link token (the one they used to open the secure-upload page), validated against the order that owns the attachment.

Every other request returns 403.

DELETE /wp-json/speccart/v1/prescription/{attachment_id} removes an uploaded prescription file. From 1.6.4 it succeeds only for:

  • staff with the manage_options capability, or
  • the logged-in customer who uploaded the file.

Earlier versions also let any visitor delete a file that was not yet attached to an order. Attachment IDs are sequential, so update to 1.6.4 or later.

On activation and on every admin hit, SpecCart writes two files into the uploads directory:

  • .htaccess: denies direct HTTP access on Apache (both 2.4 Require all denied and legacy Deny from all syntax).
  • index.html: an empty placeholder so directory indexing never reveals filenames.

If either file is deleted by a server migration or backup restore, the plugin re-creates it the next time an admin page is loaded.

nginx hosts: manual location block required

Section titled “nginx hosts: manual location block required”

nginx ignores .htaccess. If your host runs nginx (either standalone or fronting Apache), the .htaccess file is written but not read. You need a matching location block in your nginx server config:

location ^~ /wp-content/uploads/speccart-prescriptions/ {
return 403;
}

Place this rule before any generic /wp-content/uploads/ rules so it matches first. The authenticated REST endpoint (/wp-json/speccart/v1/prescriptions/{id}/file) continues to work because it’s served by PHP, not the static handler.

Admin notice when the folder answers publicly

Section titled “Admin notice when the folder answers publicly”

From 1.8.0, SpecCart checks for you whether the prescription folder can be opened from the web. It writes a small test file (speccart-probe.txt) into wp-content/uploads/speccart-prescriptions/, requests it through the site’s own address, and deletes it. When the test file comes back, every admin page shows a red notice to users who can manage the site’s options:

SpecCart: prescription uploads and fitting photos can be opened by anyone with the link, because this server ignores the plugin’s .htaccess file. Add this rule to the site’s nginx configuration: location ^~ /wp-content/uploads/speccart-prescriptions/ { deny all; }

What to do when you see it:

  1. Add the rule from the notice to the site’s nginx server block, before any generic /wp-content/uploads/ rules. deny all; and the return 403; form shown above do the same job.
  2. Reload nginx.
  3. Check with the curl commands below that the folder now answers 403.

The answer is remembered for a day, so the notice can stay for up to a day after the rule is in place. To check again at once, delete the speccart_uploads_exposed transient (for example wp transient delete speccart_uploads_exposed).

If the check gets no answer at all (the site cannot reach its own address, the server returns an error, or the folder cannot be written), no notice is shown and the check is tried again after an hour. A missing notice is therefore not proof of protection: run the checks below after any server move.

With the Measurements module switched on, fitting photos are stored in wp-content/uploads/speccart-prescriptions/fitting/, under the same directory protection. Staff open them from the order screen through /wp-json/speccart/v1/fitting-photo/{id}/view, which answers only a logged-in user with the edit_shop_orders capability. The nginx rule above covers them too.

From any machine (logged out of wp-admin):

Terminal window
# Should return 403 on a protected host.
curl -I https://your-site.example.com/wp-content/uploads/speccart-prescriptions/2026/04/any-file.jpg
# Should also return 403 when no token is supplied.
curl -I https://your-site.example.com/wp-json/speccart/v1/prescriptions/123/file

If you get 200 OK from either request, protection is not yet active for that path. Check that .htaccess exists on Apache, or that your nginx location block is in place.

Where you used to have…Replace with…
wp_get_attachment_url($id) for a prescription attachment\SpecCart\Helpers\PrescriptionFileUrl::for_attachment($id, 'staff') in admin-only contexts
A hardcoded URL in an email templateThe customer-context helper: \SpecCart\Helpers\PrescriptionFileUrl::for_attachment($id, 'customer', $user_id)
A URL in a secure-upload flow\SpecCart\Helpers\PrescriptionFileUrl::for_attachment($id, 'secure-upload', null, $magic_link_token)

Historical reminder emails sent before 1.6.0 will contain raw wp-content URLs that now return 403. Resend those emails with the new URLs if needed.

Deactivating the plugin or reverting to 1.5.0 leaves the .htaccess and index.html files in place. They’re harmless under older versions because nothing requests them. If you need to fully revert protection (not recommended), delete them manually from the uploads directory.