Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Https requests with Authorization not working via Safari

Tags:

Context

XHR requests with Authorization header over HTTPS (both together) don't reach the server, using Safari (IOS and MacOS). But it works with IE, Chrome and Firefox.

I use a valid certificate generated by Letsencrypt and browsers don't display warnings about it.

On the web inspector of Safari, these XHRs try to get result until timeout and no errors displayed.

I have one domain and no sub-domain.

Test

  • Authorization header + HTTPS => Not working
  • Authorization header + No HTTPS (HTTP) => Works
  • No authorization header + HTTPS => Works

Code

I use an interceptor to set authorization header.

this.request = (config) => {     config.headers = config.headers || {};     var authData = localStorageService.get('authorizationData');     if (authData && config.url && !config.url.endsWith("/token")) {         config.headers = {             "Authorization": 'Bearer ' + authData.access_token         };         config.withCredentials = true;     }     return config; } 

Has anyone encountered the same problems ?

UPDATE 1

There is something wrong with Safari + HTTPS + "Authorization" header. If I rename "Authorization" by "MyHeader", and doing some modification on server to retrieve my bearer token with "MyHeader" token, everything works well.

Is "Authorization" header a protected word using HTTPS on safari ?

like image 980
Nicolas Law-Dune Avatar asked Feb 28 '16 16:02

Nicolas Law-Dune


People also ask

How to prevent Safari form from trying to load a https site?

However, the https site no longer works and there is no way to prevent Safari form trying to load it. Show activity on this post. If the site has previously indicated to Safari that it wishes to always be accessed over HTTPS through HSTS ( HTTP Strict Transport Security ), then Safari will always try to redirect to HTTPS.

Why does Safari always try to redirect to https?

If the site has previously indicated to Safari that it wishes to always be accessed over HTTPS through HSTS ( HTTP Strict Transport Security ), then Safari will always try to redirect to HTTPS. You can clear the HSTS cache by deleting ~/Library/Cookies/HSTS.plist.

How do I fix the authentication issue with the web app?

The work around for me was to disable the authentication on the server, open the web app, let it load, then re enable the authentication. The web app then works. This is fine for the two devices that no longer work, but I know have to stop people upgrading until there is a fix.

How to fix Safari not responding on Mac?

Right click on the Trash icon in the Dock and select “Open”. Right click on the com.apple.Safari.plist and select “Put Back”. Select ”Replace” from the dialog when it appears. Go step by step and test. 1. If Safari is slow, stops responding, quits unexpectedly, or has other issues


2 Answers

I also faced a similar problem with safari where 'Authorization' in the header was not sent in the GET request but it ended up in a simple thing.

I simply appended a '/' at the end of the request URL and it worked for me.

for eg: change URL from '/token' to '/token/'.

like image 64
nilay jha Avatar answered Sep 18 '22 05:09

nilay jha


When an HTTP request made via safari is made to any url contains words like login, token, etc... safari automatically adds Accept-Encoding header that brokes al

like image 27
Ramon Llompart Pol Avatar answered Sep 18 '22 05:09

Ramon Llompart Pol