Skip to content

Commit 879f147

Browse files
committed
Revert sudo support - this makes more sense in the server
In practice, I think we'll always be triggering this as part of backend logic, so that's cleaner. That also neatly solves my security concerns about arbitrary commands here - we can use fixed commands in the server, since the update mechanism there is much more effective (...for now).
1 parent a233088 commit 879f147

File tree

4 files changed

+3
-50
lines changed

4 files changed

+3
-50
lines changed

package-lock.json

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
"publish": null
131131
},
132132
"dependencies": {
133-
"@expo/sudo-prompt": "^9.3.2",
134133
"@httptoolkit/util": "^0.1.8",
135134
"@sentry/electron": "^7.2.0",
136135
"electron-context-menu": "^3.5.0",

src/index.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ const rmRF = (p: string) => fs.rm(p, { recursive: true, force: true });
1818

1919
import windowStateKeeper from 'electron-window-state';
2020
import { getSystemProxy } from 'os-proxy-config';
21-
import registerContextMenu from 'electron-context-menu';
22-
import * as sudoPrompt from '@expo/sudo-prompt';
23-
import { getDeferred, delay, ErrorLike } from '@httptoolkit/util';
21+
import registerContextMenu = require('electron-context-menu');
22+
import { getDeferred, delay } from '@httptoolkit/util';
2423

2524
import { getMenu, shouldAutoHideMenu } from './menu.ts';
2625
import { ContextMenuDefinition, openContextMenu } from './context-menu.ts';
@@ -660,33 +659,3 @@ ipcMain.handle('restart-app', ipcHandler(() => {
660659
app.relaunch();
661660
app.quit();
662661
}));
663-
664-
// Prompt the user to authorize a command to run as root, for system setup we can't do
665-
// without elevated permissions. We try to avoid this, but for system config changes
666-
// it's required, and much better to do per-command than running the whole app as root.
667-
ipcMain.handle('sudo', ipcHandler(async (options: {
668-
command: string
669-
}) => {
670-
if (typeof options?.command !== 'string') {
671-
throw new Error("Invalid command for sudo");
672-
}
673-
674-
const result = getDeferred<{ success: boolean, error?: ErrorLike, stdout: string, stderr: string }>();
675-
676-
sudoPrompt.exec(options.command, {
677-
name: 'HTTP Toolkit'
678-
}, (error: unknown | null, stdout: string, stderr: string) => {
679-
// Types suggest this could be a buffer, but we want to
680-
// enforce simpler string output:
681-
stdout = stdout?.toString() ?? '';
682-
stderr = stderr?.toString() ?? '';
683-
684-
if (error) {
685-
result.resolve({ success: false, error, stdout, stderr });
686-
} else {
687-
result.resolve({ success: true, stdout, stderr });
688-
}
689-
});
690-
691-
return result.promise;
692-
}));

src/preload.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,5 @@ contextBridge.exposeInMainWorld('desktopApi', {
4646
ipcRenderer.invoke('open-context-menu', options),
4747

4848
restartApp: () =>
49-
ipcRenderer.invoke('restart-app'),
50-
51-
sudo: (options: any) =>
52-
ipcRenderer.invoke('sudo', options)
49+
ipcRenderer.invoke('restart-app')
5350
});

0 commit comments

Comments
 (0)