Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-55054] Consider a matching origin for a media request as a trusted URL when checking permissions #2893

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/permissionsManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('main/PermissionsManager', () => {
return null;
}
});
isTrustedURL.mockImplementation((url, baseURL) => baseURL.toString().startsWith(url.toString()));
isTrustedURL.mockImplementation((url, baseURL) => url.toString().startsWith(baseURL.toString()));
});

afterEach(() => {
Expand Down Expand Up @@ -188,4 +188,20 @@ describe('main/PermissionsManager', () => {
]);
expect(dialog.showMessageBox).toHaveBeenCalledTimes(1);
});

it('should still pop dialog for media requests from the servers origin', async () => {
ViewManager.getViewByWebContentsId.mockImplementation((id) => {
if (id === 2) {
return {view: {server: {url: new URL('http://anyurl.com/subpath')}}};
}

return null;
});
const permissionsManager = new PermissionsManager('anyfile.json');
permissionsManager.writeToFile = jest.fn();
const cb = jest.fn();
dialog.showMessageBox.mockReturnValue(Promise.resolve({response: 0}));
await permissionsManager.handlePermissionRequest({id: 2}, 'media', cb, {securityOrigin: 'http://anyurl.com'});
expect(dialog.showMessageBox).toHaveBeenCalled();
});
});
2 changes: 1 addition & 1 deletion src/main/permissionsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class PermissionsManager extends JsonFileManager<Permissions> {
}

// is the requesting url trusted?
if (!isTrustedURL(parsedURL, serverURL)) {
if (!(isTrustedURL(parsedURL, serverURL) || (permission === 'media' && parsedURL.origin === serverURL.origin))) {
return false;
}

Expand Down
Loading