Skip to content

Proxy with basic auth to upstream and authorization header from client #20312

@Teneff

Description

@Teneff

Describe the bug

When vite server.proxy is configured with auth option, I'm expecting basic authentication Auhorization: Basic ${Buffer.from('user:pass').toString('base64')} header to be sent to the upstream, and it is, unless the client sends own authorization header.

It's bug in http-proxy

But since it's patched using pnpm and bundled within vite either this has to be patched as well, or probably a fork of http-proxy can be made within vitejs

Reproduction

https://stackblitz.com/edit/vitejs-vite-cppgeu2m?file=src%2Fcounter.js,src%2Fmain.js,vite.config.js

Steps to reproduce

configure proxy

const proxy = {
  '/api/service1': {
    target: 'http://localhost:80/endpoint/requiring/basic-auth',
    auth: 'user1:pass1',
  },
};

export default defineConfig({
  server: {
    proxy,
  },
});
fetch('/api/service1', { headers: { authorization: "anything" } })

### System Info

```shell
not relevant

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions