capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

feat: send Referer header on ios

Open jayenashar opened this issue 4 years ago • 9 comments

Feature Request

Description

Hello, I am using a service that secures web apps using the HTTP Referer header. This service does allow the capacitor:// scheme which is default on iOS. I am having an issue were capacitor on iOS is not sending the header, even though it does send the Origin header and other headers. The service offers a js npm module which uses XMLHttpRequest. I am not having issues on Android.

Platform(s)

iOS

Preferred Solution

Add the HTTP Referer header to XMLHttpRequests.

Alternatives

Overriding XMLHttpRequest to inject the header. (Haven't tried it, yet.)

Additional Context

Attached safari debugger and found this:

GET /path HTTP/1.1
Accept: /
Origin: capacitor://localhost
Host: host.name.com
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148
Accept-Language: en-us
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

jayenashar avatar Jul 06 '20 09:07 jayenashar

The alternative doesn't work for loading images in an <img>. Any way to tell capacitor to send the Referer?

Here is the code I wrote for the alternative. It shows an error on android, as it's not allowing setting the referer. On iOS, it silently fails to add the referer.

window.XMLHttpRequest = class extends window.XMLHttpRequest {
  open(...args) {
    const retval = super.open(...args);
    this.setRequestHeader('Referer', window.location.toString());
    return retval;
  }
}

jayenashar avatar Jul 06 '20 10:07 jayenashar

Has anyone discovered or proposed any alternatives?

dducrest avatar Mar 26 '22 06:03 dducrest

you can try https://github.com/capacitor-community/http as a replacement for window.XMLHttpRequest

jayenashar avatar Mar 26 '22 07:03 jayenashar

@jayenashar i will. thank you for the suggestion.

dducrest avatar Mar 28 '22 14:03 dducrest

https://github.com/ionic-team/capacitor/pull/6387 this could fix the problem

Dante1349 avatar Apr 21 '23 23:04 Dante1349