Support NGINX $host in Downloads hotlink protection #4011
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #4010
Related: #3111
Problem
If there are two download mirrors,
slow.example.com
andfast.example.com
, hotlink protection using an NGINXsecure_link_md5
expression in the Downloads plugin cannot distinguish between these hostnames.This means that a user limited to
slow.example.com
can change the download host tofast.example.com
and download from the better mirror.Solution
To solve this,
NginxSecureLinkMd5Decorator
needs to support the NGINX$host
variable. Having this variable in the expression will lock down the secure link to the specific download host.Updated Documentation
Configure e107
Ideally, both e107 and NGINX should be configured at the exact same time, but e107 may be configured first because doing so would minimize the chance of disruption to downloaders, since the NGINX secure_link_md5 URL protection mode merely appends query string arguments to the download URL.
/e107_plugins/download/admin_download.php?mode=main&action=settings
in your web browser.secure_link_md5
expression into the NGINX secure_link_md5 expression field. This is the same expression that you put into your NGINX configuration (see the section below).Now, all downloads will have
md5
appended as a query parameter, generated from the expression you put in. If the expression contains$secure_link_expires
,expires
will be appended as a query parameter as well.Configure your NGINX download server
Set up your NGINX download location config with
secure_link_md5
to protect your downloads. For an example of how to do this, see the Using Secured URLs that Expire section of this blog post from NGINX.This is a sample
secure_link_md5
expression:$secure_link_expires$uri$remote_addr$host secret
$secure_link_expires
enables the expiration of links generated by the e107 Downloads plugin.$uri
matches the download path intended to be protected.$remote_addr
ensures that only the client's IP address may be used to download the file.$host
ensures that the token can only be used for a specific virtual host (such asfast.example.com
).secret
is a string known only to e107 and your NGINX config so that your users/downloaders cannot generate their own secure links.If your
secure_link_md5
expression contains$secure_link_expires
, thesecure_link
directive should readsecure_link $arg_md5,$arg_expires;
like in this example server block:If your
secure_link_md5
expression does not contain$secure_link_expires
, thesecure_link
directive should readsecure_link $arg_md5;
like in this example server block:If you have multiple virtual hosts and want to ensure that the secure link token cannot be used on a different hostname (e.g. prevent the client from changing
slow.example.com
tofast.example.com
for a better download mirror), add the$host
variable to thesecure_link_md5
expression like this: