@@ -124,24 +124,37 @@ func (v *paramValidator) validateHTTPSecurityScheme(
124124 request * http.Request ,
125125 pathValue string ,
126126) (bool , []* errors.ValidationError ) {
127- switch strings .ToLower (secScheme .Scheme ) {
128- case "basic" , "bearer" , "digest" :
129- if request .Header .Get ("Authorization" ) == "" {
130- validationErrors := []* errors.ValidationError {
131- {
132- Message : fmt .Sprintf ("Authorization header for '%s' scheme" , secScheme .Scheme ),
133- Reason : "Authorization header was not found" ,
134- ValidationType : helpers .SecurityValidation ,
135- ValidationSubType : secScheme .Scheme ,
136- SpecLine : sec .GoLow ().Requirements .ValueNode .Line ,
137- SpecCol : sec .GoLow ().Requirements .ValueNode .Column ,
138- HowToFix : "Add an 'Authorization' header to this request" ,
139- },
140- }
141- errors .PopulateValidationErrors (validationErrors , request , pathValue )
142- return false , validationErrors
127+ authorizationHeader := request .Header .Get ("Authorization" )
128+ if authorizationHeader == "" {
129+ validationErrors := []* errors.ValidationError {
130+ {
131+ Message : fmt .Sprintf ("Authorization header for '%s' scheme" , secScheme .Scheme ),
132+ Reason : "Authorization header was not found" ,
133+ ValidationType : helpers .SecurityValidation ,
134+ ValidationSubType : secScheme .Scheme ,
135+ SpecLine : sec .GoLow ().Requirements .ValueNode .Line ,
136+ SpecCol : sec .GoLow ().Requirements .ValueNode .Column ,
137+ HowToFix : "Add an 'Authorization' header to this request" ,
138+ },
143139 }
144- return true , nil
140+ errors .PopulateValidationErrors (validationErrors , request , pathValue )
141+ return false , validationErrors
142+ }
143+ if len (authorizationHeader ) < len (secScheme .Scheme ) || ! strings .EqualFold (authorizationHeader [:len (secScheme .Scheme )], secScheme .Scheme ) {
144+ validationErrors := []* errors.ValidationError {
145+ {
146+ Message : fmt .Sprintf ("Authorization header scheme '%s' mismatch" , secScheme .Scheme ),
147+ Reason : "Authorization header had incorrect scheme" ,
148+ ValidationType : helpers .SecurityValidation ,
149+ ValidationSubType : secScheme .Scheme ,
150+ SpecLine : sec .GoLow ().Requirements .ValueNode .Line ,
151+ SpecCol : sec .GoLow ().Requirements .ValueNode .Column ,
152+ HowToFix : fmt .Sprintf ("Use the scheme '%s' in the Authorization header " +
153+ "for this request" , secScheme .Scheme ),
154+ },
155+ }
156+ errors .PopulateValidationErrors (validationErrors , request , pathValue )
157+ return false , validationErrors
145158 }
146159 return true , nil
147160}
0 commit comments