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-61821] Automatically allow permission checks for supported permission types through for GPO configured servers #3231

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 23 additions & 1 deletion src/main/permissionsManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import {dialog, systemPreferences} from 'electron';

import Config from 'common/config';
import {parseURL, isTrustedURL} from 'common/utils/url';
import ViewManager from 'main/views/viewManager';
import CallsWidgetWindow from 'main/windows/callsWidgetWindow';
Expand Down Expand Up @@ -37,6 +38,12 @@
isTrustedURL: jest.fn(),
}));

jest.mock('common/config', () => ({
registryData: {
servers: []

Check failure on line 43 in src/main/permissionsManager.test.js

View workflow job for this annotation

GitHub Actions / build-linux

Missing trailing comma

Check failure on line 43 in src/main/permissionsManager.test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Missing trailing comma

Check failure on line 43 in src/main/permissionsManager.test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Missing trailing comma
},
}));

jest.mock('main/i18nManager', () => ({
localizeMessage: jest.fn(),
}));
Expand Down Expand Up @@ -72,6 +79,9 @@
if (id === 2) {
return {view: {server: {url: new URL('http://anyurl.com')}}};
}
if (id === 4) {
return {view: {server: {url: new URL('http://gposerver.com')}}};
}

return null;
});
Expand All @@ -84,6 +94,11 @@
}
});
isTrustedURL.mockImplementation((url, baseURL) => url.toString().startsWith(baseURL.toString()));
Config.registryData.servers = [
{
url: 'http://gposerver.com',
}

Check failure on line 100 in src/main/permissionsManager.test.js

View workflow job for this annotation

GitHub Actions / build-linux

Missing trailing comma

Check failure on line 100 in src/main/permissionsManager.test.js

View workflow job for this annotation

GitHub Actions / build-mac-no-dmg

Missing trailing comma

Check failure on line 100 in src/main/permissionsManager.test.js

View workflow job for this annotation

GitHub Actions / build-win-no-installer

Missing trailing comma
];
});

afterEach(() => {
Expand Down Expand Up @@ -115,10 +130,17 @@
it('should deny if the server URL can not be found', async () => {
const permissionsManager = new PermissionsManager('anyfile.json');
const cb = jest.fn();
await permissionsManager.handlePermissionRequest({id: 4}, 'media', cb, {securityOrigin: 'http://anyurl.com'});
await permissionsManager.handlePermissionRequest({id: 5}, 'media', cb, {securityOrigin: 'http://anyurl.com'});
expect(cb).toHaveBeenCalledWith(false);
});

it('should allow if the URL is a GPO configured server', async () => {
const permissionsManager = new PermissionsManager('anyfile.json');
const cb = jest.fn();
await permissionsManager.handlePermissionRequest({id: 4}, 'media', cb, {securityOrigin: 'http://gposerver.com'});
expect(cb).toHaveBeenCalledWith(true);
});

it('should deny if the URL is not trusted', async () => {
const permissionsManager = new PermissionsManager('anyfile.json');
const cb = jest.fn();
Expand Down
8 changes: 7 additions & 1 deletion src/main/permissionsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
OPEN_WINDOWS_MICROPHONE_PREFERENCES,
UPDATE_PATHS,
} from 'common/communication';
import Config from 'common/config';
import JsonFileManager from 'common/JsonFileManager';
import {Logger} from 'common/log';
import type {MattermostServer} from 'common/servers/MattermostServer';
Expand Down Expand Up @@ -141,7 +142,7 @@ export class PermissionsManager extends JsonFileManager<PermissionsByOrigin> {
return false;
}

let serverURL;
let serverURL: URL | undefined;
if (CallsWidgetWindow.isCallsWidget(webContentsId)) {
serverURL = CallsWidgetWindow.getViewURL();
} else {
Expand All @@ -152,6 +153,11 @@ export class PermissionsManager extends JsonFileManager<PermissionsByOrigin> {
return false;
}

// For GPO servers, we always allow permissions since they are trusted
if (Config.registryData?.servers?.some((s) => parseURL(s.url)?.href === serverURL.href)) {
davidkrauser marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

// Exception for embedded videos such as YouTube
// We still want to ask permission to do this though
const isExternalFullscreen = permission === 'fullscreen' && parsedURL.origin !== serverURL.origin;
Expand Down
Loading