Headers are sent twice in Traefik handler
Affected version
Version: 2.17.2
Platform: Traefik 3.0beta4
Summary
When using the Traefik handler, headers configured in LL::NG are sent in double to the backend app. Eg, if I set Auth-User = $uid in LL::NG, the backend app will receive
Auth-User: dani
Auth-User: dani
While it's not a problem for most app (that's why I didn't noticed it earlier), at least Django based apps are problematic as it will join all the values, separated with a comma (eg, if I try to get the user from the Auth-User header, the login will be seen as "dani,dani" instead of "dani")
Logs
Nothing particular in logs. We can only one Send header 'Auth-User' with value 'dani'
line per request
Backends used
Lemonldap::NG handler for Traefik running under uwsgi on AlmaLinux 9. Config and session backend is MariaDB
Possible fixes
The problem seems to lie in Lemonldap/NG/Handler/Server/Traefik.pm, in the handler sub. Current version is
sub handler {
my ( $self, $req ) = @_;
my @convertedHdrs = (
@{ $req->{respHeaders} },
'Content-Length' => 0,
Cookie => ( $req->env->{HTTP_COOKIE} // '' )
);
return [ 200, \@convertedHdrs, [] ];
}
Changing it like this (taken from the Nginx handler) fixes the issue
sub handler {
my ( $self, $req ) = @_;
my @convertedHdrs =
( 'Content-Length' => 0, Cookie => ( $req->env->{HTTP_COOKIE} // '' ) );
while ( my ( $k, $v ) = splice( @{ $req->{respHeaders} }, 0, 2 ) ) {
push @convertedHdrs, $k, $v;
}
return [ 200, \@convertedHdrs, [] ];
}
But I'm not sure if it's the best way to fix it.