Bug 236084 - Cache-Control is not allowed by Access-Control-Allow-Headers, intermittently
Summary: Cache-Control is not allowed by Access-Control-Allow-Headers, intermittently
Status: RESOLVED DUPLICATE of bug 233916
Alias: None
Product: WebKit
Classification: Unclassified
Component: Service Workers (show other bugs)
Version: Safari 15
Hardware: All iOS 15
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-03 08:39 PST by Zach Rattner
Modified: 2022-03-14 04:01 PDT (History)
5 users (show)

See Also:


Attachments
Console log showing the failure scenario. (65.22 KB, image/png)
2022-02-03 08:39 PST, Zach Rattner
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zach Rattner 2022-02-03 08:39:09 PST
Created attachment 450774 [details]
Console log showing the failure scenario.

We have a web app that allows for offline behavior. When offline, the API calls that the UI would make are stored in a queue. Then when the device comes back online, the service worker parses the offline request queue and syncs the activities with the server via fetch calls. We are seeing that Safari (tested on iPad Pro and Mac) intermittently refuses to execute a request with an image in the body with the following error:

Failed to load resource: Request header field Cache-Control is not allowed by Access-Control-Allow-Headers

This is strange behavior because this header is automatically added to other requests and they execute without a problem. The problem only happens when both of the following conditions are met:

(i) The network request is made from the service worker queue (in our app, this means the device was offline but is coming back online)
(ii) The network request contains blob data in the body (in our case, an image. Plain JSON calls go through without an issue)

The error does not happen unless both of the above conditions are met. But if both of the conditions are met, the error appears intermittently. Sometimes the request goes through and othertimes it is blocked. 

From MDN ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers ), "CORS-safelisted request headers are always allowed" and therefore shouldn't need to be added to Access-Control-Allow-Headers. Cache-Control is listed as a CORS-safelisted response header: https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header

We were able to work around this by adding Cache-Control to the server's Access-Control-Allow-Headers list, but it seemed like strange behavior so we wanted to report it.
Comment 1 Radar WebKit Bug Importer 2022-02-04 16:16:03 PST
<rdar://problem/88513281>
Comment 2 youenn fablet 2022-02-24 00:51:02 PST
This might be related to https://bugs.webkit.org/show_bug.cgi?id=233916.
Are you able to reproduce in latest Safari Technology Preview?
Comment 3 youenn fablet 2022-03-14 04:01:31 PDT
Please reopen if it still reproduces after fix from bug 233916.

*** This bug has been marked as a duplicate of bug 233916 ***