mirror of
https://github.com/outline/outline.git
synced 2026-12-05 10:45:07 +03:00
fix: CORS preflight (#10604)
This commit is contained in:
1 parent
959dccf119
commit
7a0e88cd3c
1 file changed
+12
-1
+12
-1
@@ -88,7 +88,18 @@ export const uploadFile = async (
|
||||
xhr.addEventListener("loadend", () => {
|
||||
resolve(xhr.readyState === 4 && xhr.status >= 200 && xhr.status < 400);
|
||||
});
|
||||
xhr.withCredentials = true;
|
||||
|
||||
// Do not send credentials if uploading to a different origin, as the combination
|
||||
// of CORS and cookies will cause preflight request failure. However S3-like storage
|
||||
// on the same host can work with credentials.
|
||||
if (data.uploadUrl.startsWith("/")) {
|
||||
xhr.withCredentials = true;
|
||||
} else {
|
||||
const parsed = new URL(data.uploadUrl);
|
||||
const requiresPreflightRequest = parsed.origin !== window.location.origin;
|
||||
xhr.withCredentials = !requiresPreflightRequest;
|
||||
}
|
||||
|
||||
xhr.open("POST", data.uploadUrl, true);
|
||||
xhr.send(formData);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user