Skip to content

Commit 6d18dba

Browse files
return error for AppendObject() API (minio#21272)
1 parent 9ea14c8 commit 6d18dba

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

cmd/api-router.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ func registerAPIRouter(router *mux.Router) {
387387
HeadersRegexp(xhttp.AmzSnowballExtract, "true").
388388
HandlerFunc(s3APIMiddleware(api.PutObjectExtractHandler, traceHdrsS3HFlag))
389389

390+
// AppendObject to be rejected
391+
router.Methods(http.MethodPut).Path("/{object:.+}").
392+
HeadersRegexp(xhttp.AmzWriteOffsetBytes, "").
393+
HandlerFunc(s3APIMiddleware(errorResponseHandler))
394+
390395
// PutObject
391396
router.Methods(http.MethodPut).Path("/{object:.+}").
392397
HandlerFunc(s3APIMiddleware(api.PutObjectHandler, traceHdrsS3HFlag))

cmd/handler-utils.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"net/textproto"
2626
"regexp"
2727
"strings"
28+
"sync/atomic"
2829

2930
"github.com/minio/madmin-go/v3"
3031
"github.com/minio/minio/internal/auth"
@@ -427,9 +428,31 @@ func errorResponseHandler(w http.ResponseWriter, r *http.Request) {
427428
HTTPStatusCode: http.StatusUpgradeRequired,
428429
}, r.URL)
429430
default:
431+
defer logger.AuditLog(r.Context(), w, r, mustGetClaimsFromToken(r))
432+
defer atomic.AddUint64(&globalHTTPStats.rejectedRequestsInvalid, 1)
433+
434+
// When we are not running in S3 Express mode, generate appropriate error
435+
// for x-amz-write-offset HEADER specified.
436+
if _, ok := r.Header[xhttp.AmzWriteOffsetBytes]; ok {
437+
tc, ok := r.Context().Value(mcontext.ContextTraceKey).(*mcontext.TraceCtxt)
438+
if ok {
439+
tc.FuncName = "s3.AppendObject"
440+
tc.ResponseRecorder.LogErrBody = true
441+
}
442+
443+
writeErrorResponse(r.Context(), w, getAPIError(ErrNotImplemented), r.URL)
444+
return
445+
}
446+
447+
tc, ok := r.Context().Value(mcontext.ContextTraceKey).(*mcontext.TraceCtxt)
448+
if ok {
449+
tc.FuncName = "s3.ValidRequest"
450+
tc.ResponseRecorder.LogErrBody = true
451+
}
452+
430453
writeErrorResponse(r.Context(), w, APIError{
431454
Code: "BadRequest",
432-
Description: fmt.Sprintf("An error occurred when parsing the HTTP request %s at '%s'",
455+
Description: fmt.Sprintf("An unsupported API call for method: %s at '%s'",
433456
r.Method, r.URL.Path),
434457
HTTPStatusCode: http.StatusBadRequest,
435458
}, r.URL)

cmd/metacache-stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ func (r *metacacheReader) Close() error {
758758
return nil
759759
}
760760

761-
// metacacheBlockWriter collects blocks and provides a callaback to store them.
761+
// metacacheBlockWriter collects blocks and provides a callback to store them.
762762
type metacacheBlockWriter struct {
763763
wg sync.WaitGroup
764764
streamErr error

internal/http/headers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ const (
181181
AmzChecksumTypeFullObject = "FULL_OBJECT"
182182
AmzChecksumTypeComposite = "COMPOSITE"
183183

184+
// S3 Express API related constant reject it.
185+
AmzWriteOffsetBytes = "x-amz-write-offset-bytes"
186+
184187
// Post Policy related
185188
AmzMetaUUID = "X-Amz-Meta-Uuid"
186189
AmzMetaName = "X-Amz-Meta-Name"

0 commit comments

Comments
 (0)