echo icon indicating copy to clipboard operation
echo copied to clipboard

x-socket-id header default causing issues.

Open stephan-v opened this issue 9 years ago • 19 comments

Why is the X-Socket-Id set per default?

This causes a shitload of problems with most API's and it would be more beneficial to add it whenever you need to call a socket endpoint, rather than to remove it when it causes problems.

The Github API for example does not allow it in their preflight response. For Axios I have to do this all over the place now:

axios.get('user/repos', {
    transformRequest: [function (data, headers) {
        delete headers['X-Socket-Id'];
        return data;
    }]
})

stephan-v avatar Oct 09 '17 23:10 stephan-v

I have same issue - L5 + UploadCare widget @latest + Echo @latest

As result UploadCare don't work

Failed to load https://upload.uploadcare.com/base/?jsonerrors=1: Request header field X-Socket-Id is not allowed by Access-Control-Allow-Headers in preflight response.

I can't unset X-Socket-Id from all 3rd party libs.

davejacksonesc avatar Oct 19 '17 17:10 davejacksonesc

Same issue here.

julesbloemen avatar Nov 02 '17 14:11 julesbloemen

Also experiencing issues with this in our app (specifically affecting Opt In Monster for customers that have us + them installed)

jwondrusch avatar Dec 04 '17 18:12 jwondrusch

I was able to fix this by putting the interceptor code above the window.echo and remove the headers for the url which did not like it.

Vue.http.interceptors.push(function (request, next) {

    //some api's dont like the X-CSFR-token or Pusher token.. remove it..
    const removeAuthHeaders = request.url.includes("openiban.com");

    request.headers['Access-Control-Allow-Origin'] = '*';

    if (removeAuthHeaders){
        request.headers.delete('Access-Control-Request-Headers')
        request.headers.delete('X-Socket-ID');

    }
    else {
        request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken);
    }



    next(function(response) {

    });
});
window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'KEYYY',
    cluster: 'CLUSTER',
    encrypted: true
});

julesbloemen avatar Dec 04 '17 18:12 julesbloemen

#157 fixed

ImJustToNy avatar Dec 09 '17 12:12 ImJustToNy

Experiencing this too as I try to geocode with Google's API.

aarondfrancis avatar Dec 19 '17 01:12 aarondfrancis

Temporary workaround is to just unset this header like this:

$.ajaxSetup({
  beforeSend: function() {}
})

After creating new Echo's instance.

ImJustToNy avatar Dec 19 '17 16:12 ImJustToNy

The x-socket-id header is required in order for Laravel to identify the socket which has caused an event to trigger. Without this, features like broadcast(new SomeEvent)->toOthers() wouldn't work.

If you don't want to send it in your headers, just take it out before you send the request.

@ImJustToNy your fix is dangerous, you won't ever be able to broadcast()->toOthers() if you do that. Fine if it works for you but the right way to do this is to wrap external requests in a separate API abstraction and remove that particular header from the request before sending rather than doing it "globally".

rohan-deshpande avatar Aug 19 '18 05:08 rohan-deshpande

@rohan-deshpande, yeah, you're right but I think echo's way of forcing it to user is incorrect. In my particular example, external lib (uploadcare) wasn't able to send request to it's CDN because of this header which was injected into jQuery's ajax method that this library uses. Took me a little while figuring what's going on. In my opinion it should be turned off by default.

ImJustToNy avatar Aug 19 '18 17:08 ImJustToNy

Echo doesn’t truly force you if you have control over your request layer.

For example I am building something with React, I’m not using jQuery, I use fetch for API requests.

Echo has provides a bunch of things to cater for Vue, jQuery or axios where it automatically intercepts request headers, so yeah I think that’s kind of not the best approach as it will bleed into other parts of the application.

Perhaps some options where you would define certain endpoints or domains where the x-socket-id is required (or the opposite) would be better.

rohan-deshpande avatar Aug 19 '18 20:08 rohan-deshpande

For example I am building something with React, I’m not using jQuery, I use fetch for API requests.

And I'm using axios, which is a default/external lib. they shouldn't break how it works.

As also mentioned above; you don't always have control over external libs. astonished this issue has been open for this long already without any indication of something going to happen.

jlsjonas avatar Sep 27 '18 09:09 jlsjonas

I think we may provide a config option for this. I think the reason why the PR was closed was because it's changed to opt-in. If we'd have a new PR which was opt-out then I think it could be accepted.

driesvints avatar Oct 31 '18 11:10 driesvints

@driesvints Actually I believe the issue is not just it being opt-out/in.

Echo should not break usage of an external library.

but the right way to do this is to wrap external requests in a separate API abstraction and remove that particular header from the request before sending rather than doing it "globally".

That's exactly what Laravel should be doing; instead of expecting 3th party libs to do this. A lot of optimizers will check if a lib already exists globally and not include it again (which is likely why the uploadcare lib that @ImJustToNy uses broke). I understand the reasons behind it but if the override is preserved it should at least check for a matching hostname before adding headers that break CORS configurations. (just my 2 cents)

jlsjonas avatar Nov 09 '18 08:11 jlsjonas

i have same issue using axios

sir-guevara avatar Jan 31 '19 12:01 sir-guevara

any updates about that issue, I've lost my mind trying fixing this one

taco-systems avatar Feb 21 '19 17:02 taco-systems

If anybody is wondering, the name of the option has been changed to: withoutInterceptors.

CaelanStewart avatar Jan 23 '20 15:01 CaelanStewart

@CaelanStewart, yeah its strange that they did the same and now its feature

ImJustToNy avatar Jan 24 '20 13:01 ImJustToNy

A good option to this would be using the native function fetch() to make requests in Javascript.

It solved my problem.

bruno-silva5 avatar Feb 03 '22 12:02 bruno-silva5

withoutInterceptor

A good option to this would be using the native function fetch() to make requests in Javascript.

It solved my problem.

This saved my day. I have had the same problem for 5 days. Thank you.

zilimuk avatar Jun 10 '22 07:06 zilimuk