Skip to content

Commit 1c63fa5

Browse files
authored
grpc: remove support for env var GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING (#9112)
Fixes #8986 This PR addresses a TODO to have this env var removed. RELEASE NOTES: - grpc: Remove support for environment variable `GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING`. Strict path checking will be enforced unconditionally, going forward.
1 parent 959af53 commit 1c63fa5

3 files changed

Lines changed: 2 additions & 63 deletions

File tree

internal/envconfig/envconfig.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,6 @@ var (
104104
// to "false".
105105
XDSRecoverPanicInResourceParsing = boolFromEnv("GRPC_GO_EXPERIMENTAL_XDS_RESOURCE_PANIC_RECOVERY", true)
106106

107-
// DisableStrictPathChecking indicates whether strict path checking is
108-
// disabled. This feature can be disabled by setting the environment
109-
// variable GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING to "true".
110-
//
111-
// When strict path checking is enabled, gRPC will reject requests with
112-
// paths that do not conform to the gRPC over HTTP/2 specification found at
113-
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md.
114-
//
115-
// When disabled, gRPC will allow paths that do not contain a leading slash.
116-
// Enabling strict path checking is recommended for security reasons, as it
117-
// prevents potential path traversal vulnerabilities.
118-
//
119-
// A future release will remove this environment variable, enabling strict
120-
// path checking behavior unconditionally.
121-
//
122-
// See
123-
// https://github.com/grpc/grpc-go/security/advisories/GHSA-p77j-4mvh-x3m3
124-
// for more details.
125-
DisableStrictPathChecking = boolFromEnv("GRPC_GO_EXPERIMENTAL_DISABLE_STRICT_PATH_CHECKING", false)
126-
127107
// EnablePriorityLBChildPolicyCache controls whether the priority balancer
128108
// should cache child balancers that are removed from the LB policy config,
129109
// for a period of 15 minutes. This is disabled by default, but can be

server.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
"google.golang.org/grpc/internal"
4343
"google.golang.org/grpc/internal/binarylog"
4444
"google.golang.org/grpc/internal/channelz"
45-
"google.golang.org/grpc/internal/envconfig"
4645
"google.golang.org/grpc/internal/grpcsync"
4746
"google.golang.org/grpc/internal/grpcutil"
4847
istats "google.golang.org/grpc/internal/stats"
@@ -150,8 +149,6 @@ type Server struct {
150149

151150
serverWorkerChannel chan func()
152151
serverWorkerChannelClose func()
153-
154-
strictPathCheckingLogEmitted atomic.Bool
155152
}
156153

157154
type serverOptions struct {
@@ -1817,26 +1814,11 @@ func (s *Server) handleStream(t transport.ServerTransport, stream *transport.Ser
18171814
}
18181815
}
18191816

1820-
sm := stream.Method()
1821-
if sm == "" {
1817+
sm, found := strings.CutPrefix(stream.Method(), "/")
1818+
if !found {
18221819
s.handleMalformedMethodName(stream, ti)
18231820
return
18241821
}
1825-
if sm[0] != '/' {
1826-
if envconfig.DisableStrictPathChecking {
1827-
if old := s.strictPathCheckingLogEmitted.Swap(true); !old {
1828-
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)
1829-
}
1830-
} else {
1831-
if old := s.strictPathCheckingLogEmitted.Swap(true); !old {
1832-
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)
1833-
}
1834-
s.handleMalformedMethodName(stream, ti)
1835-
return
1836-
}
1837-
} else {
1838-
sm = sm[1:]
1839-
}
18401822
pos := strings.LastIndex(sm, "/")
18411823
if pos == -1 {
18421824
s.handleMalformedMethodName(stream, ti)

test/malformed_method_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import (
2626

2727
"golang.org/x/net/http2"
2828
"golang.org/x/net/http2/hpack"
29-
"google.golang.org/grpc/internal/envconfig"
3029
"google.golang.org/grpc/internal/stubserver"
31-
"google.golang.org/grpc/internal/testutils"
3230

3331
testpb "google.golang.org/grpc/interop/grpc_testing"
3432
)
@@ -40,7 +38,6 @@ func (s) TestMalformedMethodPath(t *testing.T) {
4038
tests := []struct {
4139
name string
4240
path string
43-
envVar bool
4441
wantStatus string // string representation of codes.Code
4542
}{
4643
{
@@ -58,33 +55,13 @@ func (s) TestMalformedMethodPath(t *testing.T) {
5855
path: "/",
5956
wantStatus: "12", // Unimplemented
6057
},
61-
{
62-
name: "missing_leading_slash_disableStrictPathChecking_true",
63-
path: "grpc.testing.TestService/UnaryCall",
64-
envVar: true,
65-
wantStatus: "0", // OK
66-
},
67-
{
68-
name: "empty_path_disableStrictPathChecking_true",
69-
path: "",
70-
envVar: true,
71-
wantStatus: "12", // Unimplemented
72-
},
73-
{
74-
name: "just_slash_disableStrictPathChecking_true",
75-
path: "/",
76-
envVar: true,
77-
wantStatus: "12", // Unimplemented
78-
},
7958
}
8059

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

86-
testutils.SetEnvConfig(t, &envconfig.DisableStrictPathChecking, tc.envVar)
87-
8865
ss := &stubserver.StubServer{
8966
UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
9067
return &testpb.SimpleResponse{Payload: &testpb.Payload{Body: []byte("pwned")}}, nil

0 commit comments

Comments
 (0)