From 85bcacac905be0fb08696a5035dc1ce0dc89f377 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 18 Jun 2020 17:50:50 +0100 Subject: [PATCH] s3: Cap expiry duration to 1 Week and return error when sharing dir --- backend/s3/s3.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/s3/s3.go b/backend/s3/s3.go index d287375c2..9cdc53401 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -965,6 +965,7 @@ const ( memoryPoolFlushTime = fs.Duration(time.Minute) // flush the cached buffers after this long memoryPoolUseMmap = false + maxExpireDuration = fs.Duration(7 * 24 * time.Hour) // max expiry is 1 week ) // Options defines the configuration for this backend @@ -2021,9 +2022,16 @@ func (f *Fs) getMemoryPool(size int64) *pool.Pool { // PublicLink generates a public link to the remote path (usually readable by anyone) func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration, unlink bool) (link string, err error) { + if strings.HasSuffix(remote, "/") { + return "", fs.ErrorCantShareDirectories + } if _, err := f.NewObject(ctx, remote); err != nil { return "", err } + if expire > maxExpireDuration { + fs.Logf(f, "Public Link: Reducing expiry to %v as %v is greater than the max time allowed", maxExpireDuration, expire) + expire = maxExpireDuration + } bucket, bucketPath := f.split(remote) httpReq, _ := f.c.GetObjectRequest(&s3.GetObjectInput{ Bucket: &bucket,