Skip to content

Commit

Permalink
Set CSP & permissions requests handling
Browse files Browse the repository at this point in the history
  • Loading branch information
serjonya-trili committed Sep 20, 2024
1 parent a5c6949 commit ba1b392
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
1 change: 0 additions & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@emotion/is-prop-valid": "^1.3.0",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@ledgerhq/hw-transport-webusb": "^6.29.3",
"@reduxjs/toolkit": "^2.2.7",
"@tanstack/react-query": "^5.56.2",
"@tanstack/react-query-devtools": "^5.56.2",
Expand Down
42 changes: 32 additions & 10 deletions apps/desktop/public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require("path");
const url = require("url");
const process = require("process");
const { autoUpdater } = require("electron-updater");

const APP_PROTOCOL = "app";
const APP_HOST = "assets";

Expand Down Expand Up @@ -66,6 +65,38 @@ function createWindow() {
);
});

mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
"Content-Security-Policy": ["script-src 'self'"],
},
});
});

mainWindow.webContents.session.setPermissionCheckHandler((_, permission) => {
switch (permission) {
case "usb":
case "clipboard-sanitized-write":
case "background-sync":
case "accessibility-events":
return true;
default:
return false;
}
});

mainWindow.webContents.session.setPermissionRequestHandler((_, permission, callback) => {
switch (permission) {
case "clipboard-sanitized-write":
case "clipboard-read":
callback(true);
break;
default:
callback(false);
}
});

protocol.handle(APP_PROTOCOL, async req => {
try {
const uri = new URL(decodeURI(req.url));
Expand Down Expand Up @@ -107,15 +138,6 @@ function createWindow() {
}
});

mainWindow.webContents.setWindowOpenHandler(details => {
if (details.url.startsWith("https") || details.url.startsWith("mailto")) {
shell.openExternal(details.url);
return { action: "deny" };
} else {
return { action: "allow" };
}
});

// Emitted when the window is closed.
mainWindow.on("closed", () => {
// Dereference the window object, usually you would store windows
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit ba1b392

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.57% (1760/2106) 78.67% (830/1055) 78.18% (448/573)
apps/web Coverage: 83%
83.57% (1760/2106) 78.67% (830/1055) 78.18% (448/573)
packages/components Coverage: 97%
97.1% (134/138) 96.49% (55/57) 82.92% (34/41)
packages/core Coverage: 81%
82.22% (222/270) 71.73% (99/138) 81.96% (50/61)
packages/crypto Coverage: 100%
100% (28/28) 100% (3/3) 100% (5/5)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (35/35)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.59% (791/935) 80.97% (166/205) 78.72% (296/376)
packages/tezos Coverage: 86%
85.57% (89/104) 89.47% (17/19) 82.75% (24/29)
packages/tzkt Coverage: 86%
84.05% (58/69) 81.25% (13/16) 76.92% (30/39)

Please sign in to comment.