Add NGINX secure_link_md5 URL protection feature to e107 Downloads plugin #3111
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: #3075
Rationale
When e107 Downloads redirects the downloader to the download URL, the downloader can trivially hotlink to the download in the future, even with referer protection, and the e107 site admin currently cannot prevent this.
By establishing a secret between e107 and the download server, undesirable hotlinking can be prevented.
Implementation
This pull request adds a Protection tab to Downloads » Preferences to allow the configuration of secure links.
Only the NGINX secure_link_md5 protection mode has been implemented. As this is currently implemented, all downloads are affected by this mode.
A new class
NginxSecureLinkMd5Decorator
decorates mirror and direct URLs for each download to be in the expected secure link format for NGINX server blocks configured withsecure_link_md5
.Three NGINX variables are supported in this pull request:
$secure_link_expires
$uri
$remote_addr
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.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 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.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: