Skip to content
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
11 changes: 11 additions & 0 deletions apps/desktop/electron/main/live-voice/microphone-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ export function installLiveMicrophonePermissionHandlers(input: {
hasReservation: (owner: LiveOwner) => boolean;
}): void {
input.targetSession.setPermissionRequestHandler((contents, permission, callback, details) => {
// Installing a handler replaces the platform default for every permission on
// the session, and this session also carries the main renderer. Keep the
// microphone policy to `media` so unrelated web APIs keep working: denying
// the rest silently broke the app's own copy buttons, which need
// `clipboard-sanitized-write`.
if (permission !== "media") {
callback(true);
return;
}
const owner = requestOwner(input.getMainWindow(), contents, details.requestingUrl, details.isMainFrame);
const allowed = allowsLiveMicrophonePermission({
permission,
Expand All @@ -37,6 +46,8 @@ export function installLiveMicrophonePermissionHandlers(input: {
});

input.targetSession.setPermissionCheckHandler((contents, permission, requestingOrigin, details) => {
// Same scope rule as the request handler above.
if (permission !== "media") return true;
const owner = contents ? checkOwner(input.getMainWindow(), contents, requestingOrigin) : null;
return allowsLiveMicrophonePermission({
permission,
Expand Down
7 changes: 6 additions & 1 deletion apps/desktop/test/live-voice-permission.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ test("Live Voice media permission requires the trusted main frame and an active
assert.equal(requestDecision({ requestingUrl: trustedUrl, isMainFrame: false, mediaTypes: ["audio"] }), false);
assert.equal(requestDecision({ requestingUrl: "https://outside.example", isMainFrame: true, mediaTypes: ["audio"] }), false);
assert.equal(checkDecision({ mediaType: "audio" }, "https://outside.example"), false);
assert.equal(requestDecision({ requestingUrl: trustedUrl, isMainFrame: true, mediaTypes: ["audio"] }, "notifications"), false);
// Regression: the microphone policy must not shadow permissions it does not own.
// The default session carries the main renderer, where the transcript and table
// copy buttons rely on `clipboard-sanitized-write`; denying it broke them.
assert.equal(requestDecision({ requestingUrl: trustedUrl, isMainFrame: true, mediaTypes: ["audio"] }, "notifications"), true);
assert.equal(requestDecision({ requestingUrl: trustedUrl, isMainFrame: true, mediaTypes: ["audio"] }, "clipboard-sanitized-write"), true);
assert.equal(checkDecision({ mediaType: "unknown" }, "http://localhost:5173", "clipboard-sanitized-write"), true);
assert.equal(requestDecision({ requestingUrl: trustedUrl, isMainFrame: true, mediaTypes: ["audio"] }, "media", {}), false);
leaseActive = false;
assert.equal(requestDecision({ requestingUrl: trustedUrl, isMainFrame: true, mediaTypes: ["audio"] }), false);
Expand Down
Loading