@@ -133,23 +133,34 @@ func TLSConfigFromSecret(ctx context.Context, secret *corev1.Secret, opts ...TLS
133133// proxy URL. Optional "username" and "password" fields can be provided
134134// for proxy authentication.
135135func ProxyURLFromSecret (ctx context.Context , secret * corev1.Secret ) (* url.URL , error ) {
136+ ref := client .ObjectKeyFromObject (secret )
137+
136138 addressData , exists := secret .Data [KeyAddress ]
137139 if ! exists {
138140 return nil , & KeyNotFoundError {Key : KeyAddress , Secret : secret }
139141 }
140142
141143 address := string (addressData )
142144 if address == "" {
143- ref := client .ObjectKeyFromObject (secret )
144145 return nil , fmt .Errorf ("secret '%s': proxy address is empty" , ref )
145146 }
146147
148+ // Validate length before parsing to avoid parsing large invalid URLs.
149+ // The 2048 character limit matches the validation used in notification-controller's
150+ // spec.address field.
151+ if len (address ) > 2048 {
152+ return nil , fmt .Errorf ("secret '%s': proxy URL exceeds maximum length of 2048 characters" , ref )
153+ }
154+
147155 proxyURL , err := url .Parse (address )
148156 if err != nil {
149- ref := client .ObjectKeyFromObject (secret )
150157 return nil , fmt .Errorf ("secret '%s': failed to parse proxy address '%s': %w" , ref , address , err )
151158 }
152159
160+ if proxyURL .Scheme != "http" && proxyURL .Scheme != "https" {
161+ return nil , fmt .Errorf ("secret '%s': proxy URL must use http or https scheme, got '%s'" , ref , proxyURL .Scheme )
162+ }
163+
153164 username , hasUsername := secret .Data [KeyUsername ]
154165 password , hasPassword := secret .Data [KeyPassword ]
155166
0 commit comments