Skip to content

Commit a063a7a

Browse files
authored
Merge pull request DSpace#11273 from tdonohue/port_11171_to_7x
[Port dspace-7_x] Error in file upload after security fixes
2 parents 29b3ba9 + 7dd2b53 commit a063a7a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

dspace-api/src/main/java/org/dspace/storage/bitstore/DSBitStoreService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import java.util.List;
2020
import java.util.Map;
2121

22+
import org.apache.commons.lang3.StringUtils;
2223
import org.apache.logging.log4j.Logger;
2324
import org.dspace.content.Bitstream;
2425
import org.dspace.core.Utils;
26+
import org.dspace.services.factory.DSpaceServicesFactory;
2527

2628
/**
2729
* Native DSpace (or "Directory Scatter" if you prefer) asset store.
@@ -252,7 +254,10 @@ protected File getFile(Bitstream bitstream) throws IOException {
252254
}
253255
File bitstreamFile = new File(bufFilename.toString());
254256
Path normalizedPath = bitstreamFile.toPath().normalize();
255-
if (!normalizedPath.startsWith(baseDir.getAbsolutePath())) {
257+
String[] allowedAssetstoreRoots = DSpaceServicesFactory.getInstance().getConfigurationService()
258+
.getArrayProperty("assetstore.allowed.roots", new String[]{});
259+
if (!normalizedPath.startsWith(baseDir.getAbsolutePath())
260+
&& !StringUtils.startsWithAny(normalizedPath.toString(), allowedAssetstoreRoots)) {
256261
log.error("Bitstream path outside of assetstore root requested:" +
257262
"bitstream={}, path={}, assetstore={}",
258263
bitstream.getID(), normalizedPath, baseDir.getAbsolutePath());

dspace/config/modules/assetstore.cfg

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ assetstore.dir = ${dspace.dir}/assetstore
1212
# This value will be used as `incoming` default store inside the `bitstore.xml`
1313
# Possible values are:
1414
# - 0: to use the `localStore`;
15-
# - 1: to use the `s3Store`.
15+
# - 1: to use the `s3Store`.
1616
# If you want to add additional assetstores, they must be added to that bitstore.xml
1717
# and new values should be provided as key-value pairs in the `stores` map of the
18-
# `bitstore.xml` configuration.
18+
# `bitstore.xml` configuration.
1919
assetstore.index.primary = 0
2020

21+
#if the assetstore path is symbolic link, use this configuration to allow that path.
22+
#assetstore.allowed.roots = /data/assetstore
23+
2124
#---------------------------------------------------------------#
2225
#-------------- Amazon S3 Specific Configurations --------------#
2326
#---------------------------------------------------------------#
@@ -54,4 +57,4 @@ assetstore.s3.awsSecretKey =
5457

5558
# If the credentials are left empty,
5659
# then this setting is ignored and the default AWS region will be used.
57-
assetstore.s3.awsRegionName =
60+
assetstore.s3.awsRegionName =

0 commit comments

Comments
 (0)