-
Notifications
You must be signed in to change notification settings - Fork 4.7k
transport: http2 server must validates header list size when early aborting stream #8769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
23406a6
Check header size
joybestourous b12df2f
Merge branch 'master' into joy.bestourous/header-check
joybestourous 472ec38
vet
joybestourous 2ceced5
use executeAndPut for early abort header list size
joybestourous fdf518c
arjan's comments
joybestourous File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -480,11 +480,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade | |
| t.logger.Infof("Aborting the stream early: %v", errMsg) | ||
| } | ||
| t.controlBuf.put(&earlyAbortStream{ | ||
| httpStatus: http.StatusBadRequest, | ||
| streamID: streamID, | ||
| contentSubtype: s.contentSubtype, | ||
| status: status.New(codes.Internal, errMsg), | ||
| rst: !frame.StreamEnded(), | ||
| httpStatus: http.StatusBadRequest, | ||
| streamID: streamID, | ||
| contentSubtype: s.contentSubtype, | ||
| status: status.New(codes.Internal, errMsg), | ||
| rst: !frame.StreamEnded(), | ||
| maxSendHeaderListSize: t.maxSendHeaderListSize, | ||
| }) | ||
| return nil | ||
| } | ||
|
|
@@ -500,21 +501,23 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade | |
| } | ||
| if !isGRPC { | ||
| t.controlBuf.put(&earlyAbortStream{ | ||
| httpStatus: http.StatusUnsupportedMediaType, | ||
| streamID: streamID, | ||
| contentSubtype: s.contentSubtype, | ||
| status: status.Newf(codes.InvalidArgument, "invalid gRPC request content-type %q", contentType), | ||
| rst: !frame.StreamEnded(), | ||
| httpStatus: http.StatusUnsupportedMediaType, | ||
| streamID: streamID, | ||
| contentSubtype: s.contentSubtype, | ||
| status: status.Newf(codes.InvalidArgument, "invalid gRPC request content-type %q", contentType), | ||
| rst: !frame.StreamEnded(), | ||
| maxSendHeaderListSize: t.maxSendHeaderListSize, | ||
| }) | ||
| return nil | ||
| } | ||
| if headerError != nil { | ||
| t.controlBuf.put(&earlyAbortStream{ | ||
| httpStatus: http.StatusBadRequest, | ||
| streamID: streamID, | ||
| contentSubtype: s.contentSubtype, | ||
| status: headerError, | ||
| rst: !frame.StreamEnded(), | ||
| httpStatus: http.StatusBadRequest, | ||
| streamID: streamID, | ||
| contentSubtype: s.contentSubtype, | ||
| status: headerError, | ||
| rst: !frame.StreamEnded(), | ||
| maxSendHeaderListSize: t.maxSendHeaderListSize, | ||
| }) | ||
| return nil | ||
| } | ||
|
|
@@ -570,11 +573,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade | |
| t.logger.Infof("Aborting the stream early: %v", errMsg) | ||
| } | ||
| t.controlBuf.put(&earlyAbortStream{ | ||
| httpStatus: http.StatusMethodNotAllowed, | ||
| streamID: streamID, | ||
| contentSubtype: s.contentSubtype, | ||
| status: status.New(codes.Internal, errMsg), | ||
| rst: !frame.StreamEnded(), | ||
| httpStatus: http.StatusMethodNotAllowed, | ||
| streamID: streamID, | ||
| contentSubtype: s.contentSubtype, | ||
| status: status.New(codes.Internal, errMsg), | ||
| rst: !frame.StreamEnded(), | ||
| maxSendHeaderListSize: t.maxSendHeaderListSize, | ||
| }) | ||
| s.cancel() | ||
| return nil | ||
|
|
@@ -591,11 +595,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade | |
| stat = status.New(codes.PermissionDenied, err.Error()) | ||
| } | ||
| t.controlBuf.put(&earlyAbortStream{ | ||
| httpStatus: http.StatusOK, | ||
| streamID: s.id, | ||
| contentSubtype: s.contentSubtype, | ||
| status: stat, | ||
| rst: !frame.StreamEnded(), | ||
| httpStatus: http.StatusOK, | ||
| streamID: s.id, | ||
| contentSubtype: s.contentSubtype, | ||
| status: stat, | ||
| rst: !frame.StreamEnded(), | ||
| maxSendHeaderListSize: t.maxSendHeaderListSize, | ||
| }) | ||
| return nil | ||
| } | ||
|
|
@@ -605,11 +610,12 @@ func (t *http2Server) operateHeaders(ctx context.Context, frame *http2.MetaHeade | |
| t.mu.Unlock() | ||
| // Early abort in case the timeout was zero or so low it already fired. | ||
| t.controlBuf.put(&earlyAbortStream{ | ||
| httpStatus: http.StatusOK, | ||
| streamID: s.id, | ||
| contentSubtype: s.contentSubtype, | ||
| status: status.New(codes.DeadlineExceeded, context.DeadlineExceeded.Error()), | ||
| rst: !frame.StreamEnded(), | ||
| httpStatus: http.StatusOK, | ||
| streamID: s.id, | ||
| contentSubtype: s.contentSubtype, | ||
| status: status.New(codes.DeadlineExceeded, context.DeadlineExceeded.Error()), | ||
| rst: !frame.StreamEnded(), | ||
| maxSendHeaderListSize: t.maxSendHeaderListSize, | ||
| }) | ||
| return nil | ||
| } | ||
|
|
@@ -969,23 +975,32 @@ func appendHeaderFieldsFromMD(headerFields []hpack.HeaderField, md metadata.MD) | |
| return headerFields | ||
| } | ||
|
|
||
| func (t *http2Server) checkForHeaderListSize(it any) bool { | ||
| if t.maxSendHeaderListSize == nil { | ||
| // checkForHeaderListSize checks if the header list size exceeds the limit set | ||
| // by the peer. It returns false if the limit is exceeded. | ||
| func checkForHeaderListSize(hf []hpack.HeaderField, maxSendHeaderListSize *uint32) bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding a new function that accepts a That should make diff smaller. |
||
| if maxSendHeaderListSize == nil { | ||
| return true | ||
| } | ||
| hdrFrame := it.(*headerFrame) | ||
| var sz int64 | ||
| for _, f := range hdrFrame.hf { | ||
| if sz += int64(f.Size()); sz > int64(*t.maxSendHeaderListSize) { | ||
| if t.logger.V(logLevel) { | ||
| t.logger.Infof("Header list size to send violates the maximum size (%d bytes) set by client", *t.maxSendHeaderListSize) | ||
| } | ||
| for _, f := range hf { | ||
| if sz += int64(f.Size()); sz > int64(*maxSendHeaderListSize) { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| func (t *http2Server) checkForHeaderListSize(it any) bool { | ||
| hdrFrame := it.(*headerFrame) | ||
| if !checkForHeaderListSize(hdrFrame.hf, t.maxSendHeaderListSize) { | ||
| if t.logger.V(logLevel) { | ||
| t.logger.Infof("Header list size to send violates the maximum size (%d bytes) set by client", *t.maxSendHeaderListSize) | ||
| } | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| func (t *http2Server) streamContextErr(s *ServerStream) error { | ||
| select { | ||
| case <-t.done: | ||
|
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.