Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions internal/envconfig/envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ var (
// to "false".
XDSRecoverPanicInResourceParsing = boolFromEnv("GRPC_GO_EXPERIMENTAL_XDS_RESOURCE_PANIC_RECOVERY", true)

// DisableStrictPathChecking indicates whether strict path checking is
// disabled. This feature can be disabled by setting the environment
// variable GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING to "true".
//
// When strict path checking is enabled, gRPC will reject requests with
// paths that do not conform to the gRPC over HTTP/2 specification found at
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md.
//
// When disabled, gRPC will allow paths that do not contain a leading slash.
// Enabling strict path checking is recommended for security reasons, as it
// prevents potential path traversal vulnerabilities.
//
// A future release will remove this environment variable, enabling strict
// path checking behavior unconditionally.
//
// See
// https://github.com/grpc/grpc-go/security/advisories/GHSA-p77j-4mvh-x3m3
// for more details.
DisableStrictPathChecking = boolFromEnv("GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING", false)

// EnablePriorityLBChildPolicyCache controls whether the priority balancer
// should cache child balancers that are removed from the LB policy config,
// for a period of 15 minutes. This is disabled by default, but can be
Expand Down
21 changes: 2 additions & 19 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"google.golang.org/grpc/internal"
"google.golang.org/grpc/internal/binarylog"
"google.golang.org/grpc/internal/channelz"
"google.golang.org/grpc/internal/envconfig"
"google.golang.org/grpc/internal/grpcsync"
"google.golang.org/grpc/internal/grpcutil"
istats "google.golang.org/grpc/internal/stats"
Expand Down Expand Up @@ -150,8 +149,6 @@ type Server struct {

serverWorkerChannel chan func()
serverWorkerChannelClose func()

strictPathCheckingLogEmitted atomic.Bool
}

type serverOptions struct {
Expand Down Expand Up @@ -1802,25 +1799,11 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Ser
}

sm := stream.Method()
if sm == "" {
if sm == "" || sm[0] != '/' {
s.handleMalformedMethodName(stream, ti)
return
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit + optional: This can be simplified using strings.CutPrefix.

sm, found := strings.CutPrefix(sm, "/")
if !found {
    s.handleMalformedMethodName(stream, ti)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if sm[0] != '/' {
if envconfig.DisableStrictPathChecking {
if old := s.strictPathCheckingLogEmitted.Swap(true); !old {
channelz.Warningf(logger, s.channelz, "grpc: Server.handleStream received malformed method name %q. Allowing it because the environment variable GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING is set to true, but this option will be removed in a future release. See https://github.com/grpc/grpc-go/security/advisories/GHSA-p77j-4mvh-x3m3 for more information.", sm)
}
} else {
if old := s.strictPathCheckingLogEmitted.Swap(true); !old {
channelz.Warningf(logger, s.channelz, "grpc: Server.handleStream rejected malformed method name %q. To temporarily allow such requests, set the environment variable GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING to true. Note that this is not recommended as it may allow requests to bypass security policies. See https://github.com/grpc/grpc-go/security/advisories/GHSA-p77j-4mvh-x3m3 for more information.", sm)
}
s.handleMalformedMethodName(stream, ti)
return
}
} else {
sm = sm[1:]
}
sm = sm[1:]
pos := strings.LastIndex(sm, "/")
if pos == -1 {
s.handleMalformedMethodName(stream, ti)
Expand Down
23 changes: 0 additions & 23 deletions test/malformed_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import (

"golang.org/x/net/http2"
"golang.org/x/net/http2/hpack"
"google.golang.org/grpc/internal/envconfig"
"google.golang.org/grpc/internal/stubserver"
"google.golang.org/grpc/internal/testutils"

testpb "google.golang.org/grpc/interop/grpc_testing"
)
Expand All @@ -40,7 +38,6 @@ func (s) TestMalformedMethodPath(t *testing.T) {
tests := []struct {
name string
path string
envVar bool
wantStatus string // string representation of codes.Code
}{
{
Expand All @@ -58,33 +55,13 @@ func (s) TestMalformedMethodPath(t *testing.T) {
path: "/",
wantStatus: "12", // Unimplemented
},
{
name: "missing_leading_slash_disableStrictPathChecking_true",
path: "grpc.testing.TestService/UnaryCall",
envVar: true,
wantStatus: "0", // OK
},
{
name: "empty_path_disableStrictPathChecking_true",
path: "",
envVar: true,
wantStatus: "12", // Unimplemented
},
{
name: "just_slash_disableStrictPathChecking_true",
path: "/",
envVar: true,
wantStatus: "12", // Unimplemented
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()

testutils.SetEnvConfig(t, &envconfig.DisableStrictPathChecking, tc.envVar)

ss := &stubserver.StubServer{
UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
return &testpb.SimpleResponse{Payload: &testpb.Payload{Body: []byte("pwned")}}, nil
Expand Down
Loading