Skip to content

Commit 7d2d668

Browse files
Make type assertions safe
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent fa36dcb commit 7d2d668

File tree

1 file changed

+11
-3
lines changed
  • gateway/policies/api-key-auth/v1.0.0

1 file changed

+11
-3
lines changed

gateway/policies/api-key-auth/v1.0.0/apikey.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,20 @@ func (p *APIKeyPolicy) Mode() policy.ProcessingMode {
8888
// OnRequest performs API Key Authentication
8989
func (p *APIKeyPolicy) OnRequest(ctx *policy.RequestContext, params map[string]interface{}) policy.RequestAction {
9090
// Get configuration parameters
91-
keyName := params["key"].(string)
92-
location := params["in"].(string)
91+
keyName, ok := params["key"].(string)
92+
if !ok || keyName == "" {
93+
return p.handleAuthFailure(ctx, "missing or invalid 'key' configuration")
94+
}
95+
location, ok := params["in"].(string)
96+
if !ok || location == "" {
97+
return p.handleAuthFailure(ctx, "missing or invalid 'in' configuration")
98+
}
9399

94100
var valuePrefix string
95101
if valuePrefixRaw, ok := params["value-prefix"]; ok {
96-
valuePrefix = valuePrefixRaw.(string)
102+
if vp, ok := valuePrefixRaw.(string); ok {
103+
valuePrefix = vp
104+
}
97105
}
98106

99107
// Extract API key based on location

0 commit comments

Comments
 (0)