You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using *httpadapter.HandlerAdapterV2 to proxy a events.APIGatewayV2HTTPRequest, single-value headers, such as User-Agent, Authorization, etc. which may contain commas in their value, are cut into multiple http.Header values when proxying. This leads to strange behaviour with methods like *http.Request.UserAgent(), which results in a cut-off User-Agent.
Reproduction
package main
import (
"context""fmt""net/http""github.com/aws/aws-lambda-go/events""github.com/awslabs/aws-lambda-go-api-proxy/httpadapter"
)
funcExample() {
adapter:=httpadapter.NewV2(http.HandlerFunc(handler))
// User-Agent gets cut at its comma valueadapter.ProxyWithContext(context.Background(), apiGatewayV2Request())
// Output: User-Agent: Mozilla/5.0 (Linux; Android 11; Pixel 5 Build/RQ3A.210805.001.A1; wv) AppleWebKit/537.36 (KHTML
}
funcapiGatewayV2Request() events.APIGatewayV2HTTPRequest {
return events.APIGatewayV2HTTPRequest{
Headers: map[string]string{
// normal multi-valued header"Some-Multi-Value-Header": "value1,value2,value3",
// singleton header (only a single value is allowed, which can be comma-separated)"User-Agent": "Mozilla/5.0 (Linux; Android 11; Pixel 5 Build/RQ3A.210805.001.A1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.159 Mobile Safari/537.36",
},
}
}
funchandler(w http.ResponseWriter, r*http.Request) {
fmt.Printf("User-Agent: %s", r.UserAgent())
w.WriteHeader(http.StatusOK)
}
Fix
Firstly, in *RequestAccessorV2.EventToRequest one should split the header fields into single-value (singleton) headers and multi-value capabale (multitons) headers. Then parse the singletons as a single value and the multitons as a comma separted list. This fix has been implemented, see !179. I have used mozilla's list for singleton headers, as well as net/textproto.CanonicalMIMEHeaderKey to make the singleton-multiton-split case-insensitive. Test cases have also been added (disclaimer: its the first time for me to use ginkgo, hopefully what I did is correct).
The text was updated successfully, but these errors were encountered:
hohmannr
added a commit
to hohmannr/aws-lambda-go-api-proxy
that referenced
this issue
May 22, 2023
I am noticing that the Stripe-Signature header is being truncated. I am still investigating. But it's happening in my golang Lambda with Fiber v2 and this adapter.
Bug
Description
When using
*httpadapter.HandlerAdapterV2
to proxy aevents.APIGatewayV2HTTPRequest
, single-value headers, such asUser-Agent
,Authorization
, etc. which may contain commas in their value, are cut into multiplehttp.Header
values when proxying. This leads to strange behaviour with methods like*http.Request.UserAgent()
, which results in a cut-offUser-Agent
.Reproduction
Fix
Firstly, in
*RequestAccessorV2.EventToRequest
one should split the header fields into single-value (singleton) headers and multi-value capabale (multitons) headers. Then parse the singletons as a single value and the multitons as a comma separted list. This fix has been implemented, see !179. I have usedmozilla's list for singleton headers, as well as
net/textproto.CanonicalMIMEHeaderKey
to make the singleton-multiton-split case-insensitive. Test cases have also been added (disclaimer: its the first time for me to use ginkgo, hopefully what I did is correct).The text was updated successfully, but these errors were encountered: