This commit enhances application security against potential attacks by isolating dependencies that access the host system (like file operations) from the renderer process. It narrows the exposed functionality to script execution only, adding an extra security layer. The changes allow secure and scalable API exposure, preparing for future functionalities such as desktop notifications for script errors (#264), improved script execution handling (#296), and creating restore points (#50) in a secure and repeatable way. Changes include: - Inject `CodeRunner` into Vue components via dependency injection. - Move `CodeRunner` to the application layer as an abstraction for better domain-driven design alignment. - Refactor `SystemOperations` and related interfaces, removing the `I` prefix. - Update architecture documentation for clarity. - Update return types in `NodeSystemOperations` to match the Node APIs. - Improve `WindowVariablesProvider` integration tests for better error context. - Centralize type checks with common functions like `isArray` and `isNumber`. - Change `CodeRunner` to use `os` parameter, ensuring correct window variable injection. - Streamline API exposure to the renderer process: - Automatically bind function contexts to prevent loss of original context. - Implement a way to create facades (wrapper/proxy objects) for increased security.
20 lines
796 B
TypeScript
20 lines
796 B
TypeScript
// This file is used to securely expose Electron APIs to the application.
|
|
|
|
import { validateRuntimeSanity } from '@/infrastructure/RuntimeSanity/SanityChecks';
|
|
import { ElectronLogger } from '@/infrastructure/Log/ElectronLogger';
|
|
import { connectApisWithContextBridge } from './ContextBridging/ApiContextBridge';
|
|
|
|
validateRuntimeSanity({
|
|
// Validate metadata as a preventive measure for fail-fast,
|
|
// even if it's not currently used in the preload script.
|
|
validateEnvironmentVariables: true,
|
|
|
|
// The preload script cannot access variables on the window object.
|
|
validateWindowVariables: false,
|
|
});
|
|
|
|
connectApisWithContextBridge();
|
|
|
|
// Do not remove [PRELOAD_INIT]; it's a marker used in tests.
|
|
ElectronLogger.info('[PRELOAD_INIT] Preload script successfully initialized and executed.');
|