Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
272 stars 55 forks source link

[BUG] 'withCredentials' is ignored – hence cross-site usage is broken #324

Closed cr3wdayt5p closed 1 year ago

cr3wdayt5p commented 1 year ago

Hi

So far my experience with Fable.Remoting have been wonderful.

However today I ran into a bug. I have changed my hosting setup and now the frontend and backend are on two different domains. Hence I have to use CORS with credentials. But this seem to be broken i Fable.Remoting.Client.

It seems to be correct in 'Http.fs': https://github.com/Zaid-Ajaj/Fable.Remoting/blob/master/Fable.Remoting.Client/Http.fs#L68

But in 'Proxy.fs' the option is simple ignored and never passed to 'Http': https://github.com/Zaid-Ajaj/Fable.Remoting/blob/master/Fable.Remoting.Client/Proxy.fs#L113 https://github.com/Zaid-Ajaj/Fable.Remoting/blob/master/Fable.Remoting.Client/Proxy.fs#L117 https://github.com/Zaid-Ajaj/Fable.Remoting/blob/master/Fable.Remoting.Client/Proxy.fs#L143 https://github.com/Zaid-Ajaj/Fable.Remoting/blob/master/Fable.Remoting.Client/Proxy.fs#L147

All of these are:

|> Http.withHeaders headers

But needs to be:

|> Http.withHeaders headers
|> Http.withCredentials options.WithCredentials

I would consider this a pretty serious bug as it prevents usage of Fable.Remoting with a frontend on one domain and backend on another domain (assuming an authenticated use case where users are logged in – and hence cookies need to be sent).

I have tested my endpoint from dev tools on the frontend domain, and it works as expected when using:

const xhr = new XMLHttpRequest();
xhr.open('GET', '...endpoint-url...');
xhr.withCredentials = true;
xhr.send();