Protected Asset Delivery
By default the portal hands out Pimcore's public thumbnail URLs
(/cache-buster-<n>/<path>/image-thumb__<id>__<config>/<file>). The web server serves them without any permission
check, so anyone who knows or guesses such a URL gets the image, logged in or not.
With protected asset delivery the portal hands out URLs of its own thumbnail route instead. The route checks on every request that the user may view the asset in the data pool and, for a public share, that the asset belongs to the share. This only protects anything once the web server blocks Pimcore's public paths (see Web Server Rules); until then the old URLs keep working.
Configuration
pimcore_portal_engine:
asset_delivery:
mode: protected
thumbnail_max_age: 0
| Key | Values | Default |
|---|---|---|
pimcore_portal_engine.asset_delivery.mode | public, protected | public |
pimcore_portal_engine.asset_delivery.thumbnail_max_age | seconds, 0 or more | 0 |
public(the default): thumbnails are served from Pimcore's public thumbnail paths. Nothing changes for existing installs and no web server rule is needed.protected: thumbnails are served through the portal route/_portal-engine/api/asset/thumbnail/<asset id>/<thumbnail config>and its permission checks.
The option is switchable in both directions without a reindex: the search index stores a neutral reference and the URL is built when a result is read. Clear the cache after changing it.
The bundled content-page bricks (teasers, entry tiles, feature bricks) follow the setting too: their images come
from the thumbnail route in protected mode and from the public paths in public mode. Custom templates do the same
with the Twig function portalEngine_thumbnail_url (see Asset URLs).
The thumbnail URLs (their route and query parameters) are internal: only the portal builds them, and their shape can change in a later release. Don't build them by hand or rely on them in your own code or web server rules.
Images of data objects
Whoever may view a data object sees its own images, as in public mode, even without VIEW on those assets in an
asset pool. The object grants the assets in its image, hotspot image and image gallery fields (localized fields
included) and its main image, nothing else. VIEW on the object is checked in the data object pool the page belongs
to; for a public share the object has to be in the share. Images that are not the object's own still need VIEW in an
asset pool of the site.
Browser cache and revocation
thumbnail_max_age sets how many seconds a browser may reuse a thumbnail without asking the portal again
(Cache-Control: private, max-age=<seconds>). With 0, the default, the browser asks on every display and a
matching ETag answers 304, so a revoked permission takes effect on the next request. With a value above 0, a
browser that has already loaded an image keeps showing it for up to that many seconds after access to it is revoked
(or the user logs out). Pick a value that delay is acceptable for, for example 300 for five minutes.
What stays public
Images that are shown without a login cannot be protected by a session check. In protected mode these are served
by a separate public route, /_portal-engine/branding-image/<asset id>, which answers only for the images set on the
portal page document: the logo, the login background image and the e-mail image. Any other asset answers 404 there.
Static files under /bundles/... (the portal frontend build and its fallback images) are not Pimcore assets and stay
public as well.
Web Server Rules
Pimcore serves two kinds of public paths that bypass the portal:
- Thumbnails:
/(image|video)-thumb__<id>__<config>/<file>, also under/cache-buster-<n>/, cached belowpublic/var/tmp/thumbnails. - Asset originals:
/<asset path>, served frompublic/var/assets(the stock configuration whitelists the file extensions).
Block both. Keep open the portal routes (/_portal-engine/...), /bundles/... and the paths of the Pimcore admin
and Studio. Adjust the excluded prefixes below to the ones your installation uses.
Use a dedicated vhost for the portal
The Pimcore admin and Studio show their previews through the same thumbnail and asset paths. Blocking them on a host that also serves the admin breaks the admin previews. Run the portal on its own domain and virtual host (portals are Pimcore sites with their own domain anyway) and apply the rules to that host only.
nginx
Remove the stock locations for thumbnails and assets (location ~* ^(/cache-buster-\d+)?/.*/(image|video)-thumb__...
and the asset extension whitelist with try_files /var/assets$uri) from the portal's server block and add:
location ~* ^(/cache-buster-\d+)?/.*/(image|video)-thumb__\d+__ { return 403; }
location ^~ /var/assets/ { return 403; }
location ^~ /var/tmp/ { return 403; }
location ~* ^(?!/(_portal-engine|admin|pimcore-studio|bundles|static)/).+\.(jpe?g|gif|png|svgz?|webp|avif|tiff?|bmp|ico|mp[34]|mov|webm|pdf)$ { return 403; }
Apache
In the virtual host of the portal (these patterns see the path with its leading slash; in .htaccess the pattern
loses the leading slash):
RewriteEngine On
RewriteRule ^(/cache-buster-[0-9]+)?/.*/(image|video)-thumb__[0-9]+__ - [F,L]
RewriteRule ^/var/(assets|tmp)/ - [F,L]
RewriteRule ^(?!/(_portal-engine|admin|pimcore-studio|bundles|static)/).+\.(jpe?g|gif|png|svgz?|webp|avif|tiff?|bmp|ico|mp[34]|mov|webm|pdf)$ - [NC,F,L]
The rules are checked against example paths by the test ProtectedDeliveryDocsTest, but not against a running
web server: reload, then run the operator check.
Operator Check
Apply the rules only after the portal already hands out the new URLs (clear the cache first), because browsers keep old public URLs until they expire.
-
Without a login, request the public paths of an asset that is visible in a grid. Each must answer 403 or 404, never 200:
curl -sI https://portal.example/<asset path>curl -sI https://portal.example/<asset directory>/image-thumb__<id>__<config>/<file> -
Log in, open a grid and confirm that the thumbnails still load (200 from
/_portal-engine/api/asset/thumbnail/...). -
Logged out, request one of those thumbnail URLs. It must not answer 200 (401, 403 or a redirect to the login).
-
Open the login page in a private window: the logo and the background image must still show, and a mail sent by the portal must still show its image.
Performance
The thumbnail route runs PHP for every thumbnail: the Symfony kernel, the security layer and a database lookup, where a public thumbnail is a static file. A grid page with 50 thumbnails therefore causes 50 PHP requests instead of none. F1's estimate is roughly 40-120 ms per protected thumbnail against 1-3 ms for a static file; these numbers are estimates, not measurements, so measure them on your installation before relying on them:
ab -n 500 -c 10 -C "PHPSESSID=<session>" https://portal.example/<thumbnail url>
The browser can still cache the responses (Cache-Control: private with an ETag, a matching If-None-Match answers
304 without generating or reading the file); shared caches and CDNs cannot cache them. thumbnail_max_age (see
Browser cache and revocation) saves even the 304 requests, at the cost of the
revocation delay. Plan the PHP-FPM capacity
accordingly.