Skip to content

Commit 3c13ff3

Browse files
committed
Reject whitespace-only read-only and lockdown values
A value such as GITHUB_READ_ONLY=' ' trimmed to the empty string and was accepted as false, so the server still started with write tools exposed. Treat only an unset value as the default and reject a non-empty value that is blank after trimming. Fixes #3747
1 parent 3b41eca commit 3c13ff3

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎cmd/github-mcp-server/main.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,13 @@ func wordSepNormalizeFunc(_ *pflag.FlagSet, name string) pflag.NormalizedName {
398398
// turn off.
399399
func parseBoolFlag(key string) (bool, error) {
400400
raw := viper.GetString(key)
401+
if raw == "" {
402+
return false, nil
403+
}
404+
// A whitespace-only value is not a valid setting, so it falls through to
405+
// the error below instead of trimming to the unset default.
401406
switch strings.ToLower(strings.TrimSpace(raw)) {
402-
case "", "0", "f", "false", "no", "n", "off", "disabled":
407+
case "0", "f", "false", "no", "n", "off", "disabled":
403408
return false, nil
404409
case "1", "t", "true", "yes", "y", "on", "enabled":
405410
return true, nil

‎cmd/github-mcp-server/main_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ func TestParseBoolFlag(t *testing.T) {
176176
{name: "disabled", value: "disabled", want: false},
177177
{name: "typo", value: "tru", wantErr: true},
178178
{name: "garbage", value: "maybe", wantErr: true},
179+
{name: "whitespace only", value: " ", wantErr: true},
180+
{name: "padded true", value: " true ", want: true},
179181
}
180182
for _, tc := range tests {
181183
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)