Skip to content

Commit 6b860f4

Browse files
sjvanrossumYuan325
andauthored
fix(sources/postgres): apply URL encoding to query string params (#3020)
## Description Fixes an URL encoding issue in PostgreSQL connection strings. Keys and values of query parameter maps are currently not escaped during encoding, which could result in misconfiguration and poses a minor security risk if the specification of query parameter maps were to be restricted by the application or deployment tooling. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [x] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/mcp-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/mcp-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here> --------- Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com>
1 parent eb4036f commit 6b860f4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

internal/sources/postgres/postgres.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"context"
1919
"fmt"
2020
"net/url"
21-
"strings"
2221

2322
"github.com/goccy/go-yaml"
2423
"github.com/googleapis/mcp-toolbox/internal/sources"
@@ -172,11 +171,11 @@ func initPostgresConnectionPool(ctx context.Context, tracer trace.Tracer, name,
172171
}
173172

174173
func ConvertParamMapToRawQuery(queryParams map[string]string) string {
175-
queryArray := []string{}
174+
values := make(url.Values, len(queryParams))
176175
for k, v := range queryParams {
177-
queryArray = append(queryArray, fmt.Sprintf("%s=%s", k, v))
176+
values.Set(k, v)
178177
}
179-
return strings.Join(queryArray, "&")
178+
return values.Encode()
180179
}
181180

182181
func ParseQueryExecMode(queryExecMode string) (pgx.QueryExecMode, error) {

0 commit comments

Comments
 (0)