Protecting Your PrestaShop Admin URL: A Referrer-Policy Solution
Protecting Your PrestaShop Admin URL: A Referrer-Policy Solution
In the dynamic world of e-commerce, security and privacy are paramount. While PrestaShop offers robust features, subtle oversights can sometimes expose sensitive information. A recent discussion on the PrestaShop forum highlighted a common yet often overlooked issue: the potential leakage of your admin panel's "secret" URL through the browser's Referer header.
The Hidden Problem: Admin URL Exposure
Many PrestaShop merchants rely on the obscurity of their admin panel's folder name (e.g., admin123abc) as a basic security measure. However, when you navigate from your PrestaShop back office to the storefront – perhaps by clicking "View my shop" or previewing a product – your browser, by default, sends the full URL of your current page (the admin panel) to the destination page via the Referer header. This means the complete admin URL, including the secret folder name and any session tokens, can end up in:
- Server access logs
- Third-party analytics platforms
- Marketing pixels installed on your storefront
This unintended exposure undermines the "secret" nature of your admin URL and can potentially be exploited. Surprisingly, PrestaShop versions up to 9.2.0 do not natively implement the Referrer-Policy header, which is the standard web solution to control this behavior.
The Community-Driven Solution: ecom_referrerpolicy Module
Recognizing this gap, community member gusman126 (ecomyseo) has generously shared a free, open-source module designed to address this specific privacy concern: ecom_referrerpolicy.
This module adds the crucial Referrer-Policy HTTP header to both your PrestaShop storefront and admin panel, allowing you to dictate how much referrer information is shared. Here's what makes this module a valuable addition to your PrestaShop setup:
- Dual Policy Application: It applies distinct policies for the storefront and the admin panel.
- Smart Defaults:
- For the storefront:
strict-origin-when-cross-originis set by default. This value is chosen to ensure that essential functionalities like analytics tracking and affiliate programs continue to work without disruption, while still offering a good level of privacy. - For the admin panel:
no-referreris the default. This is the strictest policy, ensuring that no referrer information is sent when navigating away from the back office, effectively protecting your admin URL.
- For the storefront:
- Customizable Policies: You have the flexibility to adjust the
Referrer-Policyvalue for each zone (storefront and admin) from a selection of options, includingno-referrer,same-origin,strict-origin,strict-origin-when-cross-origin, andorigin. - Seamless Integration: The module uses a single hook (
actionDispatcherBefore) to function across PrestaShop 9's Symfony pages, the login page, and older sections of the panel. - Conflict-Free Operation: It intelligently detects and avoids overriding or duplicating existing
Referrer-Policyheaders set by other modules or server configurations. - Robust and Lightweight: Developed without overrides, Composer dependencies, database tables, or external connections, it's designed to be stable and efficient. It also gracefully handles situations where headers cannot be sent, preventing errors.
- Multistore Compatible: Store-specific settings are applied per shop, while admin panel settings are global across your multistore setup.
A Clever Workaround for PrestaShop's Quirks
One interesting detail highlighted by the module's author is PrestaShop's reliance on the Referer header for returning to specific listings in older sections of the admin panel (e.g., after activating/deactivating a carrier or cart rule). A strict no-referrer policy could potentially redirect you to the dashboard instead of the previous listing. The ecom_referrerpolicy module cleverly addresses this by restoring the necessary referrer information internally, allowing you to use the strictest policy without impacting back office usability.
Compatibility and Installation
The module is compatible with PrestaShop versions 1.7.8 through 9.2 and PHP versions 7.4 to 8.3. Installation is straightforward:
- Download the ZIP file from the GitHub repository.
- Rename the extracted folder to
ecom_referrerpolicy. - Re-compress the folder into a ZIP file.
- Upload the new ZIP file via your PrestaShop module manager.
Detailed instructions and a table explaining each Referrer-Policy value are available in the module's README file.
Important Considerations
It's important to note that if your web server (Apache, Nginx, or a CDN) already adds a Referrer-Policy header, you should disable one of the two to avoid conflicts. Additionally, this module does not apply policies to static assets like images, CSS, or JavaScript, as these are typically served directly by the web server without passing through PrestaShop – which is standard practice, as the policy of the main page is what truly matters.
This module is a fantastic example of community contribution enhancing PrestaShop's security posture. If you manage a PrestaShop store, implementing a proper Referrer-Policy is a simple yet effective step towards better privacy and security for your admin panel.