Skip to content

Commit e20dc90

Browse files
jrhynessclaude
andcommitted
fix: handle multiple X-Maas-Subscription header values from Authorino
When clients send x-maas-subscription header (even empty string), Authorino appends its injected value, resulting in multiple header values. Gin's GetHeader() returns only the first value, which could be the client's empty/incorrect value instead of Authorino's validated subscription. This fix iterates header values in reverse order and takes the last non-empty value, ensuring we use Authorino's injected subscription when available. Fixes: - test_empty_subscription_header_value: now correctly auto-selects subscription - test_api_key_ignores_subscription_header: now correctly uses API key's bound subscription Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 7e839d7 commit e20dc90

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

maas-api/internal/handlers/models.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,17 @@ func (h *ModelsHandler) ListLLMs(c *gin.Context) {
187187
// Extract x-maas-subscription header.
188188
// For API keys: Authorino injects this from auth.metadata.apiKeyValidation.subscription
189189
// For user tokens: This header is not present (Authorino doesn't inject it)
190-
requestedSubscription := strings.TrimSpace(c.GetHeader("x-maas-subscription"))
190+
// Note: If client sends x-maas-subscription header, there may be multiple values.
191+
// Authorino appends its value, so we take the last non-empty value.
192+
requestedSubscription := ""
193+
headerValues := c.Request.Header.Values("X-Maas-Subscription")
194+
for i := len(headerValues) - 1; i >= 0; i-- {
195+
trimmed := strings.TrimSpace(headerValues[i])
196+
if trimmed != "" {
197+
requestedSubscription = trimmed
198+
break
199+
}
200+
}
191201
isAPIKeyRequest := strings.HasPrefix(authHeader, "Bearer sk-oai-")
192202

193203
// Fail closed: API keys without a bound subscription must be rejected

0 commit comments

Comments
 (0)