Skip to content

Commit 85fcdac

Browse files
authored
[GH-8911] Fix file upload request when CSRF protection is enabled (#8912)
* Fix file upload for csrf protection * Fix use profile upload for csrf protection * Fix tests * Fix files.test.ts
1 parent a8ddf04 commit 85fcdac

File tree

4 files changed

+5
-0
lines changed

4 files changed

+5
-0
lines changed

app/actions/remote/user.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const user1 = {id: 'userid1', username: 'user1', email: '[email protected]',
5858
const user2 = {id: 'userid2', username: 'user2', email: '[email protected]', roles: ''} as UserProfile;
5959

6060
const mockClient = {
61+
getRequestHeaders: jest.fn(() => ({})),
6162
getMe: jest.fn(() => ({id: 'userid1', username: 'user1', email: '[email protected]', roles: ''})),
6263
getStatus: jest.fn((id: string) => ({user_id: id === 'me' ? 'userid1' : id, status: 'online'})),
6364
getProfilesInChannel: jest.fn(() => ([user1, user2])),

app/actions/remote/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ export const uploadUserProfileImage = async (serverUrl: string, localPath: strin
774774
multipart: {
775775
fileKey: 'image',
776776
},
777+
headers: client.getRequestHeaders('POST'),
777778
});
778779
}
779780
return {};

app/client/rest/files.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ test('uploadAttachment', () => {
8787
},
8888
},
8989
timeoutInterval: 180000,
90+
headers: {Accept: 'application/json'},
9091
};
9192

9293
(client.apiClient.upload as jest.Mock).mockReturnValue({
@@ -110,6 +111,7 @@ test('uploadAttachment', () => {
110111
},
111112
},
112113
timeoutInterval: 180000,
114+
headers: {Accept: 'application/json'},
113115
};
114116
client.uploadAttachment(file, channelId, onProgress, onComplete, onError);
115117
expect(client.apiClient.upload).toHaveBeenCalledWith(client.getFilesRoute(), file.localPath, expectedDefaultOptions);

app/client/rest/files.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const ClientFiles = <TBase extends Constructor<ClientBase>>(superclass: TBase) =
8181
},
8282
},
8383
timeoutInterval: toMilliseconds({minutes: 3}),
84+
headers: this.getRequestHeaders('POST'),
8485
};
8586
if (!file.localPath) {
8687
throw new Error('file does not have local path defined');

0 commit comments

Comments
 (0)