From 87b6869f478c9691b4207c9cd94a0c992bb963a2 Mon Sep 17 00:00:00 2001
From: "David R Newman (EPrints 3.4 development)" <drn@ecs.soton.ac.uk>
Date: Fri, 30 Oct 2026 16:18:36 +0000
Subject: [PATCH] Disable Upload from URL or validate URLs before uploading

---
 lib/cfg.d/document_upload.pl         | 15 +++++++++++++++
 perl_lib/EPrints/DataObj/Document.pm | 10 +++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/cfg.d/document_upload.pl b/lib/cfg.d/document_upload.pl
index 1c4593cd..64ab162b 100644
--- a/lib/cfg.d/document_upload.pl
+++ b/lib/cfg.d/document_upload.pl
@@ -13,6 +13,21 @@
 # repository administrator is sent a warning email. In kilobytes.
 $c->{diskspace_warn_threshold} = 512*1024;
 
+# Disable document "Upload from URL" by default. If you re-enable considering
+# validating URLs with "upload_url_validate" configuration below.
+$c->{plugins}->{"Screen::EPrint::UploadMethod::URL"}->{params}->{disable} = 1;
+
+# Validate a URL specified for document upload
+#$c->{upload_url_validate} = sub {
+#        my( $session, $url ) = @_;
+#
+#        # Only allow HTTPS URLs
+#        return if $url !~ /^https:/;
+#
+#        return $url;
+#};
+
+
 # Add an additional MIME type mapping from file extensions
 # $c->{mimemap}->{html} = "text/html";
 
diff --git a/perl_lib/EPrints/DataObj/Document.pm b/perl_lib/EPrints/DataObj/Document.pm
index 014e40e3..2457b2c4 100644
--- a/perl_lib/EPrints/DataObj/Document.pm
+++ b/perl_lib/EPrints/DataObj/Document.pm
@@ -1225,7 +1225,13 @@ sub upload_url
 	{
 		$url->path( "/" );
 	}
-	$self->set_value( 'upload_url', $url ); 
+
+	# Use user-defined function, if exists, to validate before allowing upload.
+	if ( my $validate_func = $self->{session}->config( "upload_url_validate" ) )
+	{
+		$url = &$validate_func( $self->{session}, $url );
+		return( 0 ) unless $url;
+	}
 
 	my $tmpdir = File::Temp->newdir();
 
@@ -1240,6 +1246,8 @@ sub upload_url
 		return( 0 );
 	}
 	
+	$self->set_value( 'upload_url', $url );
+
 	# Work out the number of directories to cut, so top-level files go in
 	# at the top level in the destination dir.
 	
