Skip to content

Commit 7d8a7ab

Browse files
committed
Allow to disable the NoPrivateNetwork protection for attachment downloads via an env variable
1 parent ad35ae6 commit 7d8a7ab

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ SAML_SP_PRIVATE_KEY="MIIE..."
121121
# In demo mode things it is not possible for a user to change his password and his settings.
122122
DEMO_MODE=0
123123

124+
# When this is set to 1, users can make Part-DB directly download a file specified as a URL from the local network and create it as a local file.
125+
# This allows users access to all resources available in the local network, which could be a security risk, so use this only if you trust your users and have a secure local network.
126+
ALLOW_ATTACHMENT_DOWNLOADS_FROM_LOCALNETWORK=0
127+
124128
# Change this to true, if no url rewriting (like mod_rewrite for Apache) is available
125129
# In that case all URL contains the index.php front controller in URL
126130
NO_URL_REWRITE_AVAILABLE=0

config/parameters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ parameters:
105105

106106
env(DATABASE_EMULATE_NATURAL_SORT): 0
107107

108+
env(ALLOW_ATTACHMENT_DOWNLOADS_FROM_LOCALNETWORK): 0
109+
108110
######################################################################################################################
109111
# Bulk Info Provider Import Configuration
110112
######################################################################################################################

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ bundled with Part-DB. Set `DATABASE_MYSQL_SSL_VERIFY_CERT` if you want to accept
8686
* `ATTACHMENT_DOWNLOAD_BY_DEFAULT`: When this is set to 1, the "download external file" checkbox is checked by default
8787
when adding a new attachment. Otherwise, it is unchecked by default. Use this if you wanna download all attachments
8888
locally by default. Attachment download is only possible, when `ALLOW_ATTACHMENT_DOWNLOADS` is set to 1.
89+
* `ALLOW_ATTACHMENT_DOWNLOADS_FROM_LOCALNETWORK` (default `0`): When this is set to 1, users can make Part-DB directly download a file specified as a URL from the local network and create it as a local file. This allows users access to all resources available in the local network, which could be a security risk, so use this only if you trust your users and have a secure local network.
8990
* `ATTACHMENT_SHOW_HTML_FILES`: When enabled, user uploaded HTML attachments can be viewed directly in the browser.
9091
Many potential malicious functions are restricted, still this is a potential security risk and should only be enabled,
9192
if you trust the users who can upload files. When set to 0, HTML files are rendered as plain text.

src/Services/Attachments/AttachmentSubmitHandler.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use App\Settings\SystemSettings\AttachmentsSettings;
4545
use Hshn\Base64EncodedFile\HttpFoundation\File\Base64EncodedFile;
4646
use Hshn\Base64EncodedFile\HttpFoundation\File\UploadedBase64EncodedFile;
47+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
4748
use Symfony\Component\HttpClient\NoPrivateNetworkHttpClient;
4849
use const DIRECTORY_SEPARATOR;
4950
use InvalidArgumentException;
@@ -77,6 +78,8 @@ public function __construct(
7778
protected FileTypeFilterTools $filterTools,
7879
protected AttachmentsSettings $settings,
7980
protected readonly SVGSanitizer $SVGSanitizer,
81+
#[Autowire(env: "bool:ALLOW_ATTACHMENT_DOWNLOADS_FROM_LOCALNETWORK")]
82+
private readonly bool $allow_local_network_downloads = false,
8083
)
8184
{
8285
//The mapping used to determine which folder will be used for an attachment type
@@ -97,7 +100,9 @@ public function __construct(
97100
LabelAttachment::class => 'label_profile',
98101
];
99102

100-
$this->httpClient = new NoPrivateNetworkHttpClient($this->httpClient);
103+
if (!$this->allow_local_network_downloads) {
104+
$this->httpClient = new NoPrivateNetworkHttpClient($this->httpClient);
105+
}
101106
}
102107

103108
/**

0 commit comments

Comments
 (0)