@@ -99,9 +99,11 @@ func safeDialer() *net.Dialer {
9999 }
100100}
101101
102+ var allowInsecureForTest = false
103+
102104func discoverJWKSURL (authURL string ) (string , error ) {
103105 u , err := url .Parse (authURL )
104- if err != nil || u .Scheme != "https" {
106+ if err != nil || ( u .Scheme != "https" && ! allowInsecureForTest ) {
105107 return "" , fmt .Errorf ("invalid or insecure auth URL: must be HTTPS" )
106108 }
107109
@@ -114,7 +116,6 @@ func discoverJWKSURL(authURL string) (string, error) {
114116 client := & http.Client {
115117 Timeout : 10 * time .Second ,
116118 Transport : & http.Transport {
117- DialContext : safeDialer ().DialContext ,
118119 ForceAttemptHTTP2 : true ,
119120 MaxIdleConns : 10 ,
120121 IdleConnTimeout : 90 * time .Second ,
@@ -126,6 +127,10 @@ func discoverJWKSURL(authURL string) (string, error) {
126127 return http .ErrUseLastResponse
127128 },
128129 }
130+
131+ if ! allowInsecureForTest {
132+ client .Transport .(* http.Transport ).DialContext = safeDialer ().DialContext
133+ }
129134
130135 resp , err := client .Get (oidcConfigURL )
131136 if err != nil {
@@ -156,7 +161,7 @@ func discoverJWKSURL(authURL string) (string, error) {
156161
157162 // Sanitize the resulting JWKS URI before returning it
158163 parsedJWKS , err := url .Parse (config .JWKSURI )
159- if err != nil || parsedJWKS .Scheme != "https" {
164+ if err != nil || ( parsedJWKS .Scheme != "https" && ! allowInsecureForTest ) {
160165 return "" , fmt .Errorf ("malicious jwks_uri detected" )
161166 }
162167
0 commit comments