Custom preset guards are skipped when the preset fails a whole-file YAML parse, while the preset is still applied
Summary
When a custom preset is applied, the security guards in applyPresetContent are skipped if the preset fails a whole-file YAML parse, while the preset is still applied from a regex-extracted slice. The result is that a preset can be applied with none of the three custom-preset checks having run, and with no operator disclosure.
This is a defense-in-depth gap, not a privilege boundary crossing: the file-loading path already fails closed, so this is reachable only from host-local state owned by the same operating-system user, which SECURITY.md states is not a trust boundary. I am reporting it publicly for that reason.
Detail
applyPresetContent derives all three custom-preset checks from one strict parse:
// src/lib/policy/index.ts:2075
const np = parseNetworkPolicies(presetContent);
parseNetworkPolicies (src/lib/policy/preset-parsing.ts:31-40) returns null when YAML.parse throws. Each guard is conditioned on that value, so each silently no-ops when it is null:
- the reserved-key check short-circuits on
np &&(:2077) - the
allowed_ipsban isfalsevianp !== null &&(:2083) validatePolicySemantics({ network_policies: null })returns no findings, becausefindDangerousHostsrequires an object record (semantic-validation.ts:64-65), so the catch-all-host check does not fire (:2101)
Execution then continues to extractPresetEntries (:459-464), which is a regex that captures everything after the first network_policies: line, and on to mergePresetIntoPolicy (:580-593) and setPolicyFile (:2247).
mergePresetIntoPolicy does re-parse strictly, but only the extracted slice. So the divergence is not strict-versus-lenient in general: the guard parses the whole file, the applier parses the tail slice. A preset whose YAML defect lies above the network_policies: line therefore fails the guard's parse and passes the applier's.
Reproduction
Against the pinned [email protected]:
preset: corp
preset: corp
network_policies:
wide_open:
endpoints:
- host: "*"
port: 443
allowed_ips: ["169.254.169.254"]
Whole-file parse (the guard path) throws Map keys must be unique at line 2, column 1, so np is null and all three checks no-op. The tail slice (the applier path) parses cleanly to:
{"wide_open":{"endpoints":[{"host":"*","port":443,"allowed_ips":["169.254.169.254"]}]}}
Operator disclosure blanks out on the same condition: preset-scope-render.ts:125-127 returns [] before emitting its heading, so the applied scope is not shown.
Scope, and what limits the impact
loadPresetFromFilealready fails closed (:2545-2549): it catches the parse error, logsInvalid YAML in <file>, and returnsnull. So--from-file/--from-dircontent cannot reach this path. The remaining callers withcustomset are the replay paths (rebuild-restore-phase.ts:287,snapshot.ts:1183), which read same-user state.- OpenShell rejects
host: "*"server-side (InvalidHostWildcard), so the reproduction above is refused atpolicy set. Theallowed_ipsban, however, is a NemoClaw-only control with no downstream equivalent, and a hostless endpoint carryingallowed_ips— the shape documented innemoclaw-blueprint/policies/presets/personal-open-internet.yaml— is accepted by OpenShell.
So the practical consequence today is that a guard the project deliberately added can be skipped without any signal, rather than an attacker crossing a boundary.
Suggested fix
Treat an unparseable custom preset as a rejection rather than as an absence of findings, matching what loadPresetFromFile already does. In the options.custom block at src/lib/policy/index.ts:2075, fail when parseNetworkPolicies(presetContent) is null.
This also matches the rationale recorded in src/lib/policy/baseline-exclusion.ts:176-181, which places an equivalent check in the replay path so that manually edited registry state cannot bypass it.
I am happy to open a PR with the change and a regression test.