Skip to content

The open alternative to Salesforce, designed for AI.

Fix front components and uploads behind cookie-authenticating proxies (#28375)

Prashant96b22ebc2ca9
diff --git a/packages/twenty-front-component-renderer/src/host/component-source/utils/__tests__/fetchComponentSourceFromNetwork.spec.ts b/packages/twenty-front-component-renderer/src/host/component-source/utils/__tests__/fetchComponentSourceFromNetwork.spec.ts
index 19b752dc0e0..454795af3c8 100644
--- a/packages/twenty-front-component-renderer/src/host/component-source/utils/__tests__/fetchComponentSourceFromNetwork.spec.ts
+++ b/packages/twenty-front-component-renderer/src/host/component-source/utils/__tests__/fetchComponentSourceFromNetwork.spec.ts
@@ -55,7 +55,7 @@ describe('fetchComponentSourceFromNetwork', () => {
expect(source).toBe('export default () => {};');
expect(fetchMock).toHaveBeenCalledWith(CACHE_BUSTED_COMPONENT_URL, {
headers: { Authorization: 'Bearer token' },
- credentials: 'omit',
+ credentials: 'same-origin',
});
});
@@ -82,10 +82,10 @@ describe('fetchComponentSourceFromNetwork', () => {
expect(source).toBe('presigned bundle source');
expect(fetchMock).toHaveBeenNthCalledWith(1, CACHE_BUSTED_COMPONENT_URL, {
headers: { Authorization: 'Bearer token' },
- credentials: 'omit',
+ credentials: 'same-origin',
});
expect(fetchMock).toHaveBeenNthCalledWith(2, PRESIGNED_URL, {
- credentials: 'omit',
+ credentials: 'same-origin',
});
});
@@ -102,7 +102,7 @@ describe('fetchComponentSourceFromNetwork', () => {
expect(fetchMock).toHaveBeenCalledWith(
`${COMPONENT_URL}?token=abc&cacheBust=v2`,
- { headers: undefined, credentials: 'omit' },
+ { headers: undefined, credentials: 'same-origin' },
);
});
diff --git a/packages/twenty-front-component-renderer/src/host/component-source/utils/__tests__/fetchJavaScriptModuleSourceText.spec.ts b/packages/twenty-front-component-renderer/src/host/component-source/utils/__tests__/fetchJavaScriptModuleSourceText.spec.ts
index 24bb4e7c9df..d82a4d8137f 100644
--- a/packages/twenty-front-component-renderer/src/host/component-source/utils/__tests__/fetchJavaScriptModuleSourceText.spec.ts
+++ b/packages/twenty-front-component-renderer/src/host/component-source/utils/__tests__/fetchJavaScriptModuleSourceText.spec.ts
@@ -18,7 +18,7 @@ describe('fetchJavaScriptModuleSourceText', () => {
).resolves.toBe('module source');
});
- it('should forward headers and omit credentials', async () => {
+ it('should forward headers and send same-origin credentials', async () => {
const fetchSpy = jest.fn(async () => ({
ok: true,
text: async () => '',
@@ -32,7 +32,10 @@ describe('fetchJavaScriptModuleSourceText', () => {
expect(fetchSpy).toHaveBeenCalledWith(
'https://api.twenty.test/core/abc.js',
- { headers: { Authorization: 'Bearer token' }, credentials: 'omit' },
+ {
+ headers: { Authorization: 'Bearer token' },
+ credentials: 'same-origin',
+ },
);
});
diff --git a/packages/twenty-front-component-renderer/src/host/component-source/utils/fetchComponentSourceFromNetwork.ts b/packages/twenty-front-component-renderer/src/host/component-source/utils/fetchComponentSourceFromNetwork.ts
index e90775efc1e..8f2e54cca63 100644
--- a/packages/twenty-front-component-renderer/src/host/component-source/utils/fetchComponentSourceFromNetwork.ts
+++ b/packages/twenty-front-component-renderer/src/host/component-source/utils/fetchComponentSourceFromNetwork.ts
@@ -31,7 +31,7 @@ export const fetchComponentSourceFromNetwork = async ({
}): Promise<string> => {
const response = await fetch(appendCacheBustQueryParameter(url), {
headers,
- credentials: 'omit',
+ credentials: 'same-origin',
});
if (!response.ok) {
@@ -53,7 +53,7 @@ export const fetchComponentSourceFromNetwork = async ({
}
const presignedResponse = await fetch(handoff.data.url, {
- credentials: 'omit',
+ credentials: 'same-origin',
});
if (!presignedResponse.ok) {
diff --git a/packages/twenty-front-component-renderer/src/host/component-source/utils/fetchJavaScriptModuleSourceText.ts b/packages/twenty-front-component-renderer/src/host/component-source/utils/fetchJavaScriptModuleSourceText.ts
index 63e93887451..e425096cd93 100644
--- a/packages/twenty-front-component-renderer/src/host/component-source/utils/fetchJavaScriptModuleSourceText.ts
+++ b/packages/twenty-front-component-renderer/src/host/component-source/utils/fetchJavaScriptModuleSourceText.ts
@@ -12,7 +12,7 @@ export const fetchJavaScriptModuleSourceText = async (
let response: Response;
try {
- response = await fetch(url, { headers, credentials: 'omit' });
+ response = await fetch(url, { headers, credentials: 'same-origin' });
} catch (error) {
throw new CustomError(
`Failed to fetch SDK client module ${url}: ${
diff --git a/packages/twenty-front/src/modules/command-menu-item/record/single-record/utils/exportBlockNoteEditorToPdf.ts b/packages/twenty-front/src/modules/command-menu-item/record/single-record/utils/exportBlockNoteEditorToPdf.ts
index 961613d3824..d7fcebb55a2 100644
--- a/packages/twenty-front/src/modules/command-menu-item/record/single-record/utils/exportBlockNoteEditorToPdf.ts
+++ b/packages/twenty-front/src/modules/command-menu-item/record/single-record/utils/exportBlockNoteEditorToPdf.ts
@@ -20,7 +20,7 @@ export const exportBlockNoteEditorToPdf = async (
try {
const response = await fetch(url, {
mode: 'cors',
- credentials: 'omit',
+ credentials: 'same-origin',
});
if (!response.ok) {
diff --git a/packages/twenty-front/src/modules/file/utils/__tests__/putFileToUploadTarget.test.ts b/packages/twenty-front/src/modules/file/utils/__tests__/putFileToUploadTarget.test.ts
new file mode 100644
index 00000000000..162f5590185
--- /dev/null
+++ b/packages/twenty-front/src/modules/file/utils/__tests__/putFileToUploadTarget.test.ts
@@ -0,0 +1,43 @@
+import { putFileToUploadTarget } from '@/file/utils/putFileToUploadTarget';
+
+const UPLOAD_TARGET = {
+ uploadUrl: 'https://crm.example.com/files/upload-id',
+ contentType: 'image/png',
+};
+
+describe('putFileToUploadTarget', () => {
+ const originalFetch = globalThis.fetch;
+
+ afterEach(() => {
+ globalThis.fetch = originalFetch;
+ });
+
+ it('should send same-origin credentials so proxy cookies reach our own origin', async () => {
+ const fetchMock = jest.fn().mockResolvedValue({ ok: true, status: 200 });
+ const file = new File(['content'], 'logo.png', { type: 'image/png' });
+ const signal = new AbortController().signal;
+
+ globalThis.fetch = fetchMock;
+
+ await putFileToUploadTarget({ file, uploadTarget: UPLOAD_TARGET, signal });
+
+ expect(fetchMock).toHaveBeenCalledWith(UPLOAD_TARGET.uploadUrl, {
+ method: 'PUT',
+ headers: { 'Content-Type': UPLOAD_TARGET.contentType },
+ body: file,
+ credentials: 'same-origin',
+ signal,
+ });
+ });
+
+ it('should throw when the upload target rejects the file', async () => {
+ globalThis.fetch = jest.fn().mockResolvedValue({ ok: false, status: 500 });
+
+ await expect(
+ putFileToUploadTarget({
+ file: new File(['content'], 'logo.png', { type: 'image/png' }),
+ uploadTarget: UPLOAD_TARGET,
+ }),
+ ).rejects.toThrow(/File upload failed \(500\)/);
+ });
+});
diff --git a/packages/twenty-front/src/modules/file/utils/putFileToUploadTarget.ts b/packages/twenty-front/src/modules/file/utils/putFileToUploadTarget.ts
index 388fefa88e4..7a9922d30bf 100644
--- a/packages/twenty-front/src/modules/file/utils/putFileToUploadTarget.ts
+++ b/packages/twenty-front/src/modules/file/utils/putFileToUploadTarget.ts
@@ -16,7 +16,7 @@ export const putFileToUploadTarget = async ({
method: 'PUT',
headers: { 'Content-Type': uploadTarget.contentType },
body: file,
- credentials: 'omit',
+ credentials: 'same-origin',
signal,
});