diff --git a/pkg/artifacts/artifacts_v4.go b/pkg/artifacts/artifacts_v4.go index 9cbe0b3c863..491f53def93 100644 --- a/pkg/artifacts/artifacts_v4.go +++ b/pkg/artifacts/artifacts_v4.go @@ -244,7 +244,7 @@ func (r *artifactV4Routes) parseProtbufBody(ctx *ArtifactContext, req protorefle ctx.Error(http.StatusInternalServerError, "Error decode request body") return false } - err = protojson.Unmarshal(body, req) + err = protojson.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(body, req) if err != nil { log.Errorf("Error decode request body: %v", err) ctx.Error(http.StatusInternalServerError, "Error decode request body") diff --git a/pkg/artifacts/server_test.go b/pkg/artifacts/server_test.go index 0591fbb9987..ef48582080f 100644 --- a/pkg/artifacts/server_test.go +++ b/pkg/artifacts/server_test.go @@ -317,6 +317,24 @@ func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) { }) } +func TestCreateArtifactV4UnknownField(t *testing.T) { + assert := assert.New(t) + + var memfs = fstest.MapFS(map[string]*fstest.MapFile{}) + + router := httprouter.New() + RoutesV4(router, "artifact/server/path", writeMapFS{memfs}, memfs) + + // Simulate upload-artifact@v7 sending an unknown field (mime_type) + body := `{"workflow_run_backend_id":"1","workflow_job_run_backend_id":"2","name":"test-artifact","version":4,"mime_type":"application/zip"}` + req, _ := http.NewRequest("POST", "http://localhost"+path.Join(ArtifactV4RouteBase, "CreateArtifact"), strings.NewReader(body)) + rr := httptest.NewRecorder() + + router.ServeHTTP(rr, req) + + assert.Equal(http.StatusOK, rr.Code, "CreateArtifact should succeed even with unknown fields like mime_type") +} + func TestMkdirFsImplSafeResolve(t *testing.T) { baseDir := "/foo/bar"