refactor(tools): remove artificial analysis ceilings
This commit is contained in:
@@ -57,8 +57,6 @@ const environmentSchema = z
|
||||
REA_BROWSER_SCENARIO_ALLOWED_ORIGINS_JSON: z.string().default("[]"),
|
||||
REA_BROWSER_SCENARIO_ALLOWED_ENV_JSON: z.string().default("[]"),
|
||||
REA_ELECTRON_OBSERVE_ENABLED: z.enum(["true", "false"]).default("false"),
|
||||
REA_ELECTRON_CDP_ENDPOINTS_JSON: z.string().default("[]"),
|
||||
REA_ELECTRON_FILE_ROOTS_JSON: z.string().default("[]"),
|
||||
REA_ELECTRON_AUTOMATE_ENABLED: z.enum(["true", "false"]).default("false"),
|
||||
REA_ELECTRON_AUTOMATE_AUTO_GRANT: z
|
||||
.enum(["true", "false"])
|
||||
@@ -68,9 +66,6 @@ const environmentSchema = z
|
||||
REA_V8_INSPECTOR_OBSERVE_ENABLED: z
|
||||
.enum(["true", "false"])
|
||||
.default("false"),
|
||||
REA_V8_INSPECTOR_ENDPOINTS_JSON: z.string().default("[]"),
|
||||
REA_V8_INSPECTOR_FILE_ROOTS_JSON: z.string().default("[]"),
|
||||
REA_V8_INSPECTOR_ALLOWED_ORIGINS_JSON: z.string().default("[]"),
|
||||
REA_JAVASCRIPT_REPLAY_ENABLED: z.enum(["true", "false"]).default("false"),
|
||||
REA_JAVASCRIPT_REPLAY_ROOTS_JSON: z.string().default("[]"),
|
||||
REA_JAVASCRIPT_REPLAY_NODE_PATH: z
|
||||
|
||||
@@ -3,7 +3,6 @@ import { isAbsolute } from "node:path";
|
||||
|
||||
import { ConfigurationError } from "../domain/errors.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { electronFileRootsSchema } from "../domain/electronObservation.js";
|
||||
|
||||
export const parseStringArray = (
|
||||
encoded: string,
|
||||
@@ -64,31 +63,6 @@ export const parseBrowserArray = (
|
||||
}
|
||||
};
|
||||
|
||||
export const parseElectronFileRoots = (
|
||||
encoded: string,
|
||||
): Result<readonly string[], ConfigurationError> => {
|
||||
try {
|
||||
const decoded: unknown = JSON.parse(encoded);
|
||||
if (Array.isArray(decoded) && decoded.length === 0) return ok([]);
|
||||
const parsed = electronFileRootsSchema.safeParse(decoded);
|
||||
return parsed.success
|
||||
? ok(parsed.data)
|
||||
: err(
|
||||
new ConfigurationError(
|
||||
"REA_ELECTRON_FILE_ROOTS_JSON must encode absolute roots",
|
||||
{ cause: parsed.error },
|
||||
),
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
return err(
|
||||
new ConfigurationError(
|
||||
"REA_ELECTRON_FILE_ROOTS_JSON must be valid JSON",
|
||||
{ cause },
|
||||
),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const parseLoaderArgs = (
|
||||
encoded: string | undefined,
|
||||
): Result<readonly string[], ConfigurationError> => {
|
||||
|
||||
@@ -6,11 +6,7 @@ import {
|
||||
browserOriginSchema,
|
||||
} from "../domain/browserObservation.js";
|
||||
import type { Environment } from "./environment.js";
|
||||
import {
|
||||
parseAbsoluteRoots,
|
||||
parseBrowserArray,
|
||||
parseElectronFileRoots,
|
||||
} from "./parsers.js";
|
||||
import { parseBrowserArray } from "./parsers.js";
|
||||
import { browserNetworkScope, permissionScope } from "./permissions.js";
|
||||
|
||||
type DisabledObservationPolicy = { readonly status: "disabled" };
|
||||
@@ -27,36 +23,12 @@ export type BrowserObservationPolicy =
|
||||
/** Parsed authority scope for passive Electron observation. */
|
||||
export type ElectronObservationPolicy =
|
||||
| DisabledObservationPolicy
|
||||
| {
|
||||
readonly status: "enabled";
|
||||
readonly cdpEndpoints: readonly [string, ...string[]];
|
||||
readonly fileRoots: readonly [string, ...string[]];
|
||||
};
|
||||
|
||||
/** Parsed location authority for passive V8 Inspector observation. */
|
||||
export type V8InspectorLocationPolicy =
|
||||
| {
|
||||
readonly scope: "files";
|
||||
readonly fileRoots: readonly [string, ...string[]];
|
||||
}
|
||||
| {
|
||||
readonly scope: "origins";
|
||||
readonly allowedOrigins: readonly [string, ...string[]];
|
||||
}
|
||||
| {
|
||||
readonly scope: "files-and-origins";
|
||||
readonly fileRoots: readonly [string, ...string[]];
|
||||
readonly allowedOrigins: readonly [string, ...string[]];
|
||||
};
|
||||
| { readonly status: "enabled" };
|
||||
|
||||
/** Parsed authority scope for passive V8 Inspector observation. */
|
||||
export type V8InspectorObservationPolicy =
|
||||
| DisabledObservationPolicy
|
||||
| {
|
||||
readonly status: "enabled";
|
||||
readonly endpoints: readonly [string, ...string[]];
|
||||
readonly locations: V8InspectorLocationPolicy;
|
||||
};
|
||||
| { readonly status: "enabled" };
|
||||
|
||||
/** Complete parsed passive-observation policy family. */
|
||||
export interface PassiveObservationPolicies {
|
||||
@@ -92,23 +64,6 @@ export const appendPassiveObservationCeilings = (
|
||||
appendV8InspectorCeiling(ceilings, policies.v8Inspector);
|
||||
};
|
||||
|
||||
/** Project the legal file and origin scopes from an enabled V8 policy. */
|
||||
export const v8InspectorLocationScopes = (
|
||||
locations: V8InspectorLocationPolicy,
|
||||
): {
|
||||
readonly fileRoots: readonly string[];
|
||||
readonly allowedOrigins: readonly string[];
|
||||
} => {
|
||||
switch (locations.scope) {
|
||||
case "files":
|
||||
return { fileRoots: locations.fileRoots, allowedOrigins: [] };
|
||||
case "origins":
|
||||
return { fileRoots: [], allowedOrigins: locations.allowedOrigins };
|
||||
case "files-and-origins":
|
||||
return locations;
|
||||
}
|
||||
};
|
||||
|
||||
const parseBrowserObservationPolicy = (
|
||||
env: Environment,
|
||||
): Result<BrowserObservationPolicy, ConfigurationError> => {
|
||||
@@ -148,99 +103,17 @@ const parseBrowserObservationPolicy = (
|
||||
const parseElectronObservationPolicy = (
|
||||
env: Environment,
|
||||
): Result<ElectronObservationPolicy, ConfigurationError> => {
|
||||
const endpoints = parseBrowserArray(
|
||||
env.REA_ELECTRON_CDP_ENDPOINTS_JSON,
|
||||
"REA_ELECTRON_CDP_ENDPOINTS_JSON",
|
||||
browserEndpointSchema,
|
||||
16,
|
||||
);
|
||||
if (!endpoints.ok) return endpoints;
|
||||
const roots = parseElectronFileRoots(env.REA_ELECTRON_FILE_ROOTS_JSON);
|
||||
if (!roots.ok) return roots;
|
||||
if (env.REA_ELECTRON_OBSERVE_ENABLED !== "true")
|
||||
return ok({ status: "disabled" });
|
||||
const parsedEndpoints = requireFirst(
|
||||
endpoints.value,
|
||||
"REA_ELECTRON_CDP_ENDPOINTS_JSON must encode at least one loopback endpoint when Electron observation is enabled",
|
||||
);
|
||||
if (!parsedEndpoints.ok) return parsedEndpoints;
|
||||
const parsedRoots = requireFirst(
|
||||
roots.value,
|
||||
"REA_ELECTRON_FILE_ROOTS_JSON must encode at least one absolute root when Electron observation is enabled",
|
||||
);
|
||||
if (!parsedRoots.ok) return parsedRoots;
|
||||
return ok({
|
||||
status: "enabled",
|
||||
cdpEndpoints: parsedEndpoints.value,
|
||||
fileRoots: parsedRoots.value,
|
||||
});
|
||||
return ok({ status: "enabled" });
|
||||
};
|
||||
|
||||
const parseV8InspectorObservationPolicy = (
|
||||
env: Environment,
|
||||
): Result<V8InspectorObservationPolicy, ConfigurationError> => {
|
||||
const endpoints = parseBrowserArray(
|
||||
env.REA_V8_INSPECTOR_ENDPOINTS_JSON,
|
||||
"REA_V8_INSPECTOR_ENDPOINTS_JSON",
|
||||
browserEndpointSchema,
|
||||
16,
|
||||
);
|
||||
if (!endpoints.ok) return endpoints;
|
||||
const roots = parseAbsoluteRoots(
|
||||
env.REA_V8_INSPECTOR_FILE_ROOTS_JSON,
|
||||
"REA_V8_INSPECTOR_FILE_ROOTS_JSON",
|
||||
);
|
||||
if (!roots.ok) return roots;
|
||||
const origins = parseBrowserArray(
|
||||
env.REA_V8_INSPECTOR_ALLOWED_ORIGINS_JSON,
|
||||
"REA_V8_INSPECTOR_ALLOWED_ORIGINS_JSON",
|
||||
browserOriginSchema,
|
||||
32,
|
||||
);
|
||||
if (!origins.ok) return origins;
|
||||
if (env.REA_V8_INSPECTOR_OBSERVE_ENABLED !== "true")
|
||||
return ok({ status: "disabled" });
|
||||
const parsedEndpoints = requireFirst(
|
||||
endpoints.value,
|
||||
"REA_V8_INSPECTOR_ENDPOINTS_JSON must encode at least one loopback endpoint when V8 Inspector observation is enabled",
|
||||
);
|
||||
if (!parsedEndpoints.ok) return parsedEndpoints;
|
||||
const locations = parseV8Locations(roots.value, origins.value);
|
||||
if (!locations.ok) return locations;
|
||||
return ok({
|
||||
status: "enabled",
|
||||
endpoints: parsedEndpoints.value,
|
||||
locations: locations.value,
|
||||
});
|
||||
};
|
||||
|
||||
const parseV8Locations = (
|
||||
roots: readonly string[],
|
||||
origins: readonly string[],
|
||||
): Result<V8InspectorLocationPolicy, ConfigurationError> => {
|
||||
const [firstRoot, ...remainingRoots] = roots;
|
||||
const [firstOrigin, ...remainingOrigins] = origins;
|
||||
if (firstRoot !== undefined && firstOrigin !== undefined)
|
||||
return ok({
|
||||
scope: "files-and-origins",
|
||||
fileRoots: [firstRoot, ...remainingRoots],
|
||||
allowedOrigins: [firstOrigin, ...remainingOrigins],
|
||||
});
|
||||
if (firstRoot !== undefined)
|
||||
return ok({
|
||||
scope: "files",
|
||||
fileRoots: [firstRoot, ...remainingRoots],
|
||||
});
|
||||
if (firstOrigin !== undefined)
|
||||
return ok({
|
||||
scope: "origins",
|
||||
allowedOrigins: [firstOrigin, ...remainingOrigins],
|
||||
});
|
||||
return err(
|
||||
new ConfigurationError(
|
||||
"V8 Inspector observation requires at least one file root or exact origin when enabled",
|
||||
),
|
||||
);
|
||||
return ok({ status: "enabled" });
|
||||
};
|
||||
|
||||
const requireFirst = (
|
||||
@@ -272,8 +145,7 @@ const appendElectronCeiling = (
|
||||
): void => {
|
||||
if (policy.status === "disabled") return;
|
||||
ceilings.push(
|
||||
permissionScope("electron_observe", policy.fileRoots, {
|
||||
origins: policy.cdpEndpoints,
|
||||
permissionScope("electron_observe", [], {
|
||||
network: "loopback",
|
||||
}),
|
||||
);
|
||||
@@ -284,10 +156,8 @@ const appendV8InspectorCeiling = (
|
||||
policy: V8InspectorObservationPolicy,
|
||||
): void => {
|
||||
if (policy.status === "disabled") return;
|
||||
const scopes = v8InspectorLocationScopes(policy.locations);
|
||||
ceilings.push(
|
||||
permissionScope("v8_inspector_observe", scopes.fileRoots, {
|
||||
origins: [...policy.endpoints, ...scopes.allowedOrigins],
|
||||
permissionScope("v8_inspector_observe", [], {
|
||||
network: "loopback",
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user