Improve desktop security by isolating Electron
Enable `contextIsolation` in Electron to securely expose a limited set of Node.js APIs to the renderer process. It: 1. Isolates renderer and main process contexts. It ensures that the powerful main process functions aren't directly accessible from renderer process(es), adding a security boundary. 2. Mitigates remote exploitation risks. By isolating contexts, potential malicious code injections in the renderer can't directly reach and compromise the main process. 3. Reduces attack surface. 4. Protect against prototype pollution: It prevents tampering of JavaScript object prototypes in one context from affecting another context, improving app reliability and security. Supporting changes include: - Extract environment and system operations classes to the infrastructure layer. This removes node dependencies from core domain and application code. - Introduce `ISystemOperations` to encapsulate OS interactions. Use it from `CodeRunner` to isolate node API usage. - Add a preloader script to inject validated environment variables into renderer context. This keeps Electron integration details encapsulated. - Add new sanity check to fail fast on issues with preloader injected variables. - Improve test coverage of runtime sanity checks and environment components. Move validation logic into separate classes for Single Responsibility. - Improve absent value test case generation.
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
import { it } from 'vitest';
|
||||
|
||||
export function itEachAbsentStringValue(runner: (absentValue: string) => void): void {
|
||||
itEachAbsentTestCase(AbsentStringTestCases, runner);
|
||||
export function itEachAbsentStringValue(
|
||||
runner: (absentValue: string) => void,
|
||||
options: IAbsentTestCaseOptions = DefaultAbsentTestCaseOptions,
|
||||
): void {
|
||||
itEachAbsentTestCase(getAbsentStringTestCases(options), runner);
|
||||
}
|
||||
|
||||
export function itEachAbsentObjectValue(
|
||||
runner: (absentValue: AbsentObjectType) => void,
|
||||
options: IAbsentTestCaseOptions = DefaultAbsentTestCaseOptions,
|
||||
): void {
|
||||
itEachAbsentTestCase(AbsentObjectTestCases, runner);
|
||||
itEachAbsentTestCase(getAbsentObjectTestCases(options), runner);
|
||||
}
|
||||
|
||||
export function itEachAbsentCollectionValue<T>(runner: (absentValue: []) => void): void {
|
||||
itEachAbsentTestCase(getAbsentCollectionTestCases<T>(), runner);
|
||||
export function itEachAbsentCollectionValue<T>(
|
||||
runner: (absentValue: []) => void,
|
||||
options: IAbsentTestCaseOptions = DefaultAbsentTestCaseOptions,
|
||||
): void {
|
||||
itEachAbsentTestCase(getAbsentCollectionTestCases<T>(options), runner);
|
||||
}
|
||||
|
||||
export function itEachAbsentTestCase<T>(
|
||||
@@ -25,28 +32,40 @@ export function itEachAbsentTestCase<T>(
|
||||
}
|
||||
}
|
||||
|
||||
export const AbsentObjectTestCases: readonly IAbsentTestCase<AbsentObjectType>[] = [
|
||||
{
|
||||
valueName: 'undefined',
|
||||
absentValue: undefined,
|
||||
},
|
||||
{
|
||||
valueName: 'null',
|
||||
absentValue: null,
|
||||
},
|
||||
];
|
||||
|
||||
export const AbsentStringTestCases: readonly IAbsentStringCase[] = [
|
||||
{
|
||||
valueName: 'empty',
|
||||
absentValue: '',
|
||||
},
|
||||
...AbsentObjectTestCases,
|
||||
];
|
||||
|
||||
export function getAbsentCollectionTestCases<T>(): readonly IAbsentCollectionCase<T>[] {
|
||||
export function getAbsentObjectTestCases(
|
||||
options: IAbsentTestCaseOptions = DefaultAbsentTestCaseOptions,
|
||||
): IAbsentTestCase<AbsentObjectType>[] {
|
||||
return [
|
||||
...AbsentObjectTestCases,
|
||||
{
|
||||
valueName: 'null',
|
||||
absentValue: null,
|
||||
},
|
||||
...(options.excludeUndefined ? [] : [
|
||||
{
|
||||
valueName: 'undefined',
|
||||
absentValue: undefined,
|
||||
},
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
export function getAbsentStringTestCases(
|
||||
options: IAbsentTestCaseOptions = DefaultAbsentTestCaseOptions,
|
||||
): IAbsentStringCase[] {
|
||||
return [
|
||||
{
|
||||
valueName: 'empty',
|
||||
absentValue: '',
|
||||
},
|
||||
...getAbsentObjectTestCases(options),
|
||||
];
|
||||
}
|
||||
|
||||
export function getAbsentCollectionTestCases<T>(
|
||||
options: IAbsentTestCaseOptions = DefaultAbsentTestCaseOptions,
|
||||
): readonly IAbsentCollectionCase<T>[] {
|
||||
return [
|
||||
...getAbsentObjectTestCases(options),
|
||||
{
|
||||
valueName: 'empty',
|
||||
absentValue: new Array<T>(),
|
||||
@@ -54,6 +73,14 @@ export function getAbsentCollectionTestCases<T>(): readonly IAbsentCollectionCas
|
||||
];
|
||||
}
|
||||
|
||||
const DefaultAbsentTestCaseOptions: IAbsentTestCaseOptions = {
|
||||
excludeUndefined: false,
|
||||
};
|
||||
|
||||
interface IAbsentTestCaseOptions {
|
||||
readonly excludeUndefined: boolean;
|
||||
}
|
||||
|
||||
type AbsentObjectType = undefined | null;
|
||||
|
||||
interface IAbsentTestCase<T> {
|
||||
|
||||
Reference in New Issue
Block a user