fix: discard unknown fields in protobuf unmarshal for artifact v4 API#6039
Open
majiayu000 wants to merge 2 commits intonektos:masterfrom
Open
fix: discard unknown fields in protobuf unmarshal for artifact v4 API#6039majiayu000 wants to merge 2 commits intonektos:masterfrom
majiayu000 wants to merge 2 commits intonektos:masterfrom
Conversation
upload-artifact@v7 sends a mime_type field in CreateArtifact requests
that is not defined in the proto schema, causing strict unmarshalling
to fail. Use protojson.UnmarshalOptions{DiscardUnknown: true} to
silently ignore unknown fields, which is the standard approach for
forward-compatible protobuf handling.
Fixes nektos#6022
Signed-off-by: majiayu000 <1835304752@qq.com>
Verify that the CreateArtifact v4 endpoint correctly handles request bodies containing unknown protobuf fields (e.g. mime_type sent by upload-artifact@v7) by returning HTTP 200 instead of 500. Signed-off-by: majiayu000 <1835304752@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6022
Summary
upload-artifact@v7sends new fields (e.g.mime_type) inCreateArtifactrequests that are not in the proto definition (artifact.pb.go). The default strictprotojson.Unmarshalrejects these, causing a 500 error.This changes
parseProtbufBodyinpkg/artifacts/artifacts_v4.goto useprotojson.UnmarshalOptions{DiscardUnknown: true}, which silently ignores unknown fields. This is the standard approach for forward-compatible protobuf handling.Changes
pkg/artifacts/artifacts_v4.go: UseUnmarshalOptions{DiscardUnknown: true}instead of plainprotojson.Unmarshalpkg/artifacts/server_test.go: Add unit test verifyingCreateArtifactsucceeds when request contains unknown fieldsTest Plan
go test ./pkg/artifacts/...passesTestCreateArtifactWithUnknownFieldssends a request body with an extramime_typefield and asserts HTTP 200