-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced hotlink prevention & hotlink management
- Loading branch information
1 parent
53a94a4
commit 64bb988
Showing
18 changed files
with
326 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
description: Protect your download links by preventing downloads from other domains. | ||
--- | ||
|
||
# Hotlinking | ||
|
||
Hotlinking (also known as leeching) is when another website links directly to your downloadable content. For a variety of reasons, you probably don't want your content to be downloadable from other websites. | ||
|
||
:::warning Prevented by default since v2.3 (in Craft 4) and v3.1 (in Craft 5) | ||
Once hotlink prevention was introduced, prevention became the default behavior for all new links. | ||
::: | ||
|
||
## Allowing Hotlinks | ||
|
||
Hotlinking from other websites is **forbidden by default.** When necessary, there are two ways to configure hotlinking: | ||
|
||
### Option 1 - Configure availability per each link | ||
|
||
For maximum control, configure the availability of individual links when [creating each token](/creating-a-token/#createtoken-asset-options). | ||
|
||
Use the `allowHotlinks` option to configure exactly how hotlinks should be allowed. | ||
|
||
### Option 2 - Configure availability globally via plugin's Settings | ||
|
||
For global control, edit the plugin's Settings page. Set the "Allow Hotlinks" field to manage the availability of all links in the system. | ||
|
||
<img width="520" :src="$withBase('/images/allow-hotlinks.png')" class="dropshadow" alt=""> | ||
|
||
If the option to "only hotlink from specified sites" is selected, you'll then be prompted to specify a whitelist of friendly domains. | ||
|
||
<img width="520" :src="$withBase('/images/hotlink-domain-whitelist.png')" class="dropshadow" alt=""> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/migrations/m240408_000000_digitalDownload_addAllowHotlinksColumn.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Digital Download plugin for Craft CMS | ||
* | ||
* Provide secure digital download links to your files. | ||
* | ||
* @author Double Secret Agency | ||
* @link https://www.doublesecretagency.com/ | ||
* @copyright Copyright (c) 2016 Double Secret Agency | ||
*/ | ||
|
||
namespace doublesecretagency\digitaldownload\migrations; | ||
|
||
use craft\db\Migration; | ||
use yii\base\NotSupportedException; | ||
|
||
/** | ||
* Migration: Add allowHotlinks column | ||
* @since 3.1.0 | ||
*/ | ||
class m240408_000000_digitalDownload_addAllowHotlinksColumn extends Migration | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
* @throws NotSupportedException | ||
*/ | ||
public function safeUp(): void | ||
{ | ||
$table = '{{%digitaldownload_tokens}}'; | ||
if (!$this->db->columnExists($table, 'allowHotlinks')) { | ||
$this->addColumn($table, 'allowHotlinks', $this->string()->after('token')); | ||
} | ||
$this->update($table, ['allowHotlinks' => 'all']); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m240408_000000_digitalDownload_addAllowHotlinksColumn cannot be reverted.\n"; | ||
|
||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.