Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copyProxyResHeadersToUserRes overwrites Set-Cookie headers that have already been set by previous middleware #547

Open
fabb opened this issue Aug 16, 2024 · 3 comments · May be fixed by #548

Comments

@fabb
Copy link

fabb commented Aug 16, 2024

We have some middlewares before the proxy middleware to handle setting cookies (like authentication and others).
We set cookies like this in previous middlewares: res.cookie('name', 'value').

Responses that are proxies do not contain these Set-Cookie headers though. Other headers seem to pass fine.

We do not use userResHeaderDecorator.

express-http-proxy should not remove any Set-Cookie headers that have already been set on the response object.

@fabb
Copy link
Author

fabb commented Aug 16, 2024

The problem is this line: https://github.com/villadora/express-http-proxy/blob/master/app/steps/copyProxyResHeadersToUserRes.js#L13

It looks like if the proxied backend returns Set-Cookie header, it overwrites these headers if they were already set on the user response object.

The problem is that there is no workaround using userResHeaderDecorator because copyProxyResHeadersToUserRes runs before it and already deleted the headers.

@fabb fabb changed the title Removes Set-Cookie headers that have already been set by previous middleware copyProxyResHeadersToUserRes overwrites Set-Cookie headers that have already been set by previous middleware Aug 16, 2024
fabb added a commit to fabb/express-http-proxy that referenced this issue Aug 17, 2024
@monkpow
Copy link
Collaborator

monkpow commented Aug 20, 2024

@fabb Thanks for the detailed report and fix. I'll review this week.

@fabb
Copy link
Author

fabb commented Oct 2, 2024

@monkpow friendly reminder 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants