502 PH Error caused by poorly implemented backend. Work arounds?

I have a backend that I need to pipe through HAProxy (The User Control Panel of FreePBX).

My issue is that the Sangoma developers maintain this “we known better” attitude even though their backend code is poorly written.

Here is a dump of the response headers: https://pastebin.com/DNiYBUtq

Notice that the Set-Cookie header is repeated 41 times!

How can I convince HAProxy to pass this through?

There is only a single Set-Cookie header in your dump, and the PHPSESSID is on its own line. Can you please make sure the dump is accurate.

With what you posted, no browser would ever actually install the PHPSESSID cookie, and I do believe that is not the case, otherwise the entire application would not work.

So please send the actual and correct dump of the response headers.