aboutsummaryrefslogtreecommitdiff
path: root/src/net/url/url.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/url/url.go')
-rw-r--r--src/net/url/url.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/net/url/url.go b/src/net/url/url.go
index 3acd202c24..202957a3a2 100644
--- a/src/net/url/url.go
+++ b/src/net/url/url.go
@@ -929,7 +929,30 @@ func ParseQuery(query string) (Values, error) {
return m, err
}
+var urlmaxqueryparams = godebug.New("urlmaxqueryparams")
+
+const defaultMaxParams = 10000
+
+func urlParamsWithinMax(params int) bool {
+ withinDefaultMax := params <= defaultMaxParams
+ if urlmaxqueryparams.Value() == "" {
+ return withinDefaultMax
+ }
+ customMax, err := strconv.Atoi(urlmaxqueryparams.Value())
+ if err != nil {
+ return withinDefaultMax
+ }
+ withinCustomMax := customMax == 0 || params < customMax
+ if withinDefaultMax != withinCustomMax {
+ urlmaxqueryparams.IncNonDefault()
+ }
+ return withinCustomMax
+}
+
func parseQuery(m Values, query string) (err error) {
+ if !urlParamsWithinMax(strings.Count(query, "&") + 1) {
+ return errors.New("number of URL query parameters exceeded limit")
+ }
for query != "" {
var key string
key, query, _ = strings.Cut(query, "&")