Fix thumbnails status code

Return 403 instead of 500 when the image is too large (in dimensions or file
size).

Fixes: #10589
This commit is contained in:
Ralf Haferkamp
2024-11-18 13:14:45 +01:00
committed by Ralf Haferkamp
parent 8a903991b8
commit e0cf17d5e5
2 changed files with 25 additions and 8 deletions

View File

@@ -0,0 +1,9 @@
Bugfix: Fix status code for thumbnail requests
We fixed the status code returned by the thumbnails service when the image
source for a thumbnail exceeds the configured maximum dimensions or file size.
The service now returns a 403 Forbidden status code instead of a 500 Internal
Server Error status code.
https://github.com/owncloud/ocis/pull/10592
https://github.com/owncloud/ocis/issues/10589

View File

@@ -22,6 +22,7 @@ import (
"github.com/owncloud/ocis/v2/ocis-pkg/log"
thumbnailssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/thumbnails/v0"
terrors "github.com/owncloud/ocis/v2/services/thumbnails/pkg/errors"
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/preprocessor"
"github.com/owncloud/ocis/v2/services/thumbnails/pkg/service/grpc/v0/decorators"
tjwt "github.com/owncloud/ocis/v2/services/thumbnails/pkg/service/jwt"
@@ -155,9 +156,13 @@ func (g Thumbnail) handleCS3Source(ctx context.Context, req *thumbnailssvc.GetTh
ctx = imgsource.ContextSetAuthorization(ctx, src.GetAuthorization())
r, err := g.cs3Source.Get(ctx, src.GetPath())
if err != nil {
switch {
case errors.Is(err, terrors.ErrImageTooLarge):
return "", merrors.Forbidden(g.serviceID, err.Error())
case err != nil:
return "", merrors.InternalServerError(g.serviceID, "could not get image from source: %s", err.Error())
}
defer r.Close()
ppOpts := map[string]interface{}{
"fontFileMap": g.preprocessorOpts.TxtFontFileMap,
@@ -169,10 +174,10 @@ func (g Thumbnail) handleCS3Source(ctx context.Context, req *thumbnailssvc.GetTh
}
key, err = g.manager.Generate(tr, img)
if err != nil {
return "", err
if errors.Is(err, terrors.ErrImageTooLarge) {
return "", merrors.Forbidden(g.serviceID, err.Error())
}
return key, nil
return key, err
}
func (g Thumbnail) handleWebdavSource(ctx context.Context, req *thumbnailssvc.GetThumbnailRequest) (string, error) {
@@ -244,7 +249,10 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *thumbnailssvc.Ge
imgURL.RawQuery = params.Encode()
r, err := g.webdavSource.Get(ctx, imgURL.String())
if err != nil {
switch {
case errors.Is(err, terrors.ErrImageTooLarge):
return "", merrors.Forbidden(g.serviceID, err.Error())
case err != nil:
return "", merrors.InternalServerError(g.serviceID, "could not get image from source: %s", err.Error())
}
defer r.Close()
@@ -258,10 +266,10 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *thumbnailssvc.Ge
}
key, err = g.manager.Generate(tr, img)
if err != nil {
return "", err
if errors.Is(err, terrors.ErrImageTooLarge) {
return "", merrors.Forbidden(g.serviceID, err.Error())
}
return key, nil
return key, err
}
func (g Thumbnail) stat(path, auth string) (*provider.StatResponse, error) {