super-productivity/electron/electronAPI.d.ts
Johannes Millan 7f029b1798
fix(plugins): harden nodeExecution grants (#8205)
* fix(plugins): harden node execution grants

* fix(plugins): harden iframe bridge boundaries (#8208)

* fix(plugins): harden iframe bridge boundaries

* fix(plugins): tighten iframe bridge follow-up

* test(plugins): make node-executor electron test hermetic

The new plugin-node-executor test read the real built-in plugin manifest
(src/assets/bundled-plugins/sync-md/manifest.json), which is a build
artifact absent when 'npm run test:electron' runs in CI (before the
frontend/plugin build). Stub the manifest read, scoped to the executor
module via Module._load, so the grant/token/webContents assertions no
longer depend on built plugin assets.

* fix(plugins): allow iframe formatDate & getCurrentLanguage i18n methods

The iframe API allow-list gate added in #8208 only listed a subset of
the i18n methods that master's #8146 exposes to iframe plugins. Without
this, plugin calls to formatDate/getCurrentLanguage (and translate) are
rejected with 'Unknown API method'. Add all three so the merged gate
matches the methods createBoundMethods/createPluginApiScript expose.

* docs(plugins): document node-exec handoff bootstrap-ordering invariant

The one-shot consumePluginNodeExecutionApi() handoff is defended by
construction ordering, not structural isolation: PluginBridgeService must
consume it before any plugin 'new Function' code runs (both share window.ea
in one renderer realm). Document the invariant at the consumption site so a
future lazy-service/early-plugin-load refactor can't silently regress it.
Surfaced by the post-merge security review (latent finding; not currently
exploitable).

* fix(plugins): use static iframe sandbox attribute to avoid NG0910

Binding a security-sensitive iframe attribute (sandbox) via [attr.sandbox]
makes Angular throw RuntimeError NG0910 and tear down the iframe, crashing
the plugin view to the global error screen. This broke the plugin-iframe,
plugin-loading and plugin-lifecycle e2e tests.

Restore the static sandbox attribute (still without allow-same-origin, so
the opaque-origin isolation from #8208 is preserved) and drop the now-unused
iframeSandbox binding/import.
2026-06-09 18:16:41 +02:00

249 lines
6.2 KiB
TypeScript

import { IpcRendererEvent } from 'electron';
import {
GlobalConfigState,
TakeABreakConfig,
TaskWidgetConfig,
} from '../src/app/features/config/global-config.model';
import { KeyboardConfig } from '../src/app/features/config/keyboard-config.model';
import { JiraCfg } from '../src/app/features/issue/providers/jira/jira.model';
import { AppDataCompleteLegacy } from '../src/app/imex/sync/sync.model';
import { Task } from '../src/app/features/tasks/task.model';
import { LocalBackupMeta } from '../src/app/imex/local-backup/local-backup.model';
import { AppDataComplete } from '../src/app/op-log/model/model-config';
import {
PluginNodeScriptRequest,
PluginNodeScriptResult,
} from '../packages/plugin-api/src/types';
import {
LocalRestApiRequestPayload,
LocalRestApiResponsePayload,
} from './shared-with-frontend/local-rest-api.model';
import { ElectronDistChannel } from './shared-with-frontend/get-dist-channel';
export interface PluginNodeExecutionElectronApi {
requestGrant(pluginId: string): Promise<{ token: string } | null>;
executeScript(
pluginId: string,
grantToken: string,
request: PluginNodeScriptRequest,
): Promise<PluginNodeScriptResult>;
revokeGrant(pluginId: string, grantToken: string): Promise<void>;
}
export interface ElectronAPI {
on(
channel: string,
listener: (event: IpcRendererEvent, ...args: unknown[]) => void,
): void;
// SYNC
// ----
getDistChannel(): ElectronDistChannel | null;
// INVOKE
// ------
getUserDataPath(): Promise<string>;
getBackupPath(): Promise<string>;
checkBackupAvailable(): Promise<false | LocalBackupMeta>;
loadBackupData(backupPath: string): Promise<string>;
fileSyncSave(args: {
filePath: string;
localRev: string | null;
dataStr: string;
}): Promise<string | Error>;
fileSyncLoad(args: {
filePath: string;
localRev: string | null;
}): Promise<{ rev: string; dataStr: string | undefined } | Error>;
fileSyncRemove(args: { filePath: string }): Promise<unknown | Error>;
fileSyncListFiles(args: { dirPath: string }): Promise<string[] | Error>;
checkDirExists(args: { dirPath: string }): Promise<true | Error>;
pickDirectory(): Promise<string | undefined>;
showOpenDialog(options: {
properties: string[];
title?: string;
defaultPath?: string;
filters?: { name: string; extensions: string[] }[];
}): Promise<string[] | undefined>;
toFileUrl(filePath: string): Promise<string>;
readLocalImageAsDataUrl(filePathOrUrl: string): Promise<string | null>;
// checkDirExists(dirPath: string): Promise<true | Error>;
// STANDARD
// --------
setZoomFactor(zoomFactor: number): void;
getZoomFactor(): number;
openPath(path: string): void;
openExternalUrl(url: string): void;
saveFileDialog(
filename: string,
data: string,
): Promise<{ success: boolean; path?: string }>;
shareNative(payload: {
text?: string;
url?: string;
title?: string;
files?: string[];
}): Promise<{ success: boolean; error?: string }>;
isLinux(): boolean;
isGnomeDesktop(): boolean;
isMacOS(): boolean;
isAppleSilicon(): boolean;
isSnap(): boolean;
isFlatpak(): boolean;
// CLIPBOARD IMAGES
// ----------------
saveClipboardImage(
basePath: string,
fileName: string,
base64Data: string,
mimeType: string,
): Promise<string>;
loadClipboardImage(
basePath: string,
imageId: string,
): Promise<{ base64: string; mimeType: string } | null>;
deleteClipboardImage(basePath: string, imageId: string): Promise<boolean>;
listClipboardImages(
basePath: string,
): Promise<{ id: string; mimeType: string; createdAt: number; size: number }[]>;
getClipboardImagePath(basePath: string, imageId: string): Promise<string | null>;
getClipboardFilePaths(): Promise<string[]>;
copyClipboardImageFile(
basePath: string,
filePath: string,
): Promise<{
id: string;
mimeType: string;
size: number;
createdAt: number;
} | null>;
readClipboardImage(basePath: string): Promise<{
id: string;
mimeType: string;
size: number;
createdAt: number;
} | null>;
getPathForFile(file: File): string | null;
// SEND
// ----
reloadMainWin(): void;
openDevTools(): void;
showEmojiPanel(): void;
relaunch(): void;
exit(exitCode: number): void;
shutdownNow(): void;
flashFrame(): void;
showOrFocus(): void;
lockScreen(): void;
informAboutAppReady(): void;
scheduleRegisterBeforeClose(id: string): void;
unscheduleRegisterBeforeClose(id: string): void;
setDoneRegisterBeforeClose(id: string): void;
setProgressBar(args: {
progress: number;
progressBarMode: 'normal' | 'pause' | 'none';
}): void;
sendAppSettingsToElectron(globalCfg: GlobalConfigState): void;
sendSettingsUpdate(globalCfg: GlobalConfigState): void;
updateTaskWidgetSettings(cfg: TaskWidgetConfig): void;
updateTitleBarDarkMode(isDarkMode: boolean): void;
registerGlobalShortcuts(keyboardConfig: KeyboardConfig): void;
showFullScreenBlocker(args: { msg?: string; takeABreakCfg: TakeABreakConfig }): void;
// TODO use invoke instead
makeJiraRequest(args: {
requestId: string;
url: string;
requestInit: RequestInit;
jiraCfg: JiraCfg;
}): void;
jiraSetupImgHeaders(args: { jiraCfg: JiraCfg }): void;
backupAppData(args: {
data: AppDataCompleteLegacy | AppDataComplete;
maxBackupFiles?: number | null;
}): void;
updateCurrentTask(
task: Task | null,
isPomodoroEnabled: boolean,
currentPomodoroSessionTime: number,
isFocusModeEnabled?: boolean,
currentFocusSessionTime?: number,
focusModeMode?: string,
);
updateTodayTasks(
tasks: { id: string; title: string; timeEstimate: number; timeSpent: number }[],
): void;
onSwitchTask(listener: (taskId: string) => void): void;
exec(command: string): void;
consumePluginNodeExecutionApi(): PluginNodeExecutionElectronApi | null;
// Plugin OAuth
pluginOAuthPrepare(): Promise<{ port: number }>;
pluginOAuthStart(url: string): void;
onPluginOAuthCb(
listener: (data: { code?: string; error?: string; state?: string }) => void,
): void;
onLocalRestApiRequest(listener: (payload: LocalRestApiRequestPayload) => void): void;
sendLocalRestApiResponse(payload: LocalRestApiResponsePayload): void;
}