Development Gotchas & Pitfalls#
This document tracks non-obvious behaviors, common pitfalls, and architectural "gotchas" in the opnDossier codebase to assist future maintainers and contributors.
1. Testing & Concurrency#
1.1 t.Parallel() and Global State#
The cmd/ package uses package-level global variables for CLI flags (required by spf13/cobra for flag binding). Never use t.Parallel() in any test that modifies or relies on these global variables.
- Problem: Concurrent tests modifying
sharedDeviceType,sharedAuditMode, or therootCmdflag set will cause non-deterministic data races. - Symptom:
just test-racefails with "DATA RACE" reports in thecmdpackage. - Solution: Remove
t.Parallel()from the parent test and all subtests that interact with global flags. Uset.Cleanup()to restore original global values after the test. - Enforcement: The
.golangci.ymlforbidigorule forbidst.Parallel()anywhere incmd/— catches the regression at lint time, which is the only automated gate for this class. The race detector is local-only, viajust test-race(orjust ci-check); it is deliberately not a CI job — see § 1.7. A prior pre-pushjust ci-checkhook broke non-interactive push clients, so the full gate is still not wired to a git hook. See CONTRIBUTING.md § Git Hooks for the current setup.
1.2 Race Detector Collateral#
When a data race occurs in a test touching global state, the Go race detector may report collateral races in unrelated, stateless functions (e.g., truncateString or escapePipeForMarkdown) that happen to be running in other parallel tests.
- Rule of Thumb: If a stateless utility function is reporting a race, check if a concurrent test is modifying a global variable.
1.3 require.* Inside Goroutine Bodies Fails testifylint go-require#
require.NoError / require.NotNil and other require.* calls invoke t.FailNow, which is only valid on the test's main goroutine. The testifylint linter (go-require rule) flags any require.* inside a goroutine body — golangci-lint run will fail at commit time even when the test passes at runtime.
- Pattern: collect per-goroutine outcomes into shared slices, then assert with
require.*from the main test goroutine afterwg.Wait(). - Live example of the safe side: the concurrent
prepareForExporttest ininternal/converter/enrichment_test.goruns eight goroutines that report failures witht.Errorfrather thanrequire.*, so the linter is satisfied and no goroutine callsFailNow. When you need a halt-the-test assertion, collect each goroutine's outcome into a shared slice and run therequire.*loop afterwg.Wait()on the main goroutine. assert.*is fine inside goroutines — it doesn't callFailNow. Useassertfor soft checks during the goroutine,requirefor halt-the-test checks after the join.
1.4 goconst Trips on Fixture-Derived String Duplication#
The goconst linter flags string literals appearing 3+ times in the same package. Tests that hand-write a hostname or other fixture-derived string already present in generateSmallConfig/generateLargeConfig add a fourth occurrence and fail lint.
- Wrong:
expected := "small-config"in a new test. - Right:
expected := smallConfig.System.Hostname— sources from the fixture and stays in sync if the fixture changes. - Avoid extracting a package-level constant unless you're going to refactor the fixture builders to use it too — partial extraction keeps the lint warning and adds drift surface.
1.5 gocognit Threshold Is 40, Not the Default#
The .golangci.yml gocognit linter is configured to fail at cognitive complexity > 40 (the default is 30). Table-driven benchmark functions that fan out 4+ sub-benchmarks via b.Run routinely trip it — BenchmarkMultiFormatExport (NATS-37) was the canonical case.
- Fix pattern: extract per-variant closures into helper functions returning
func(*testing.B)(e.g.,runMultiFormatGenerate(ctx, gen, device, formats, preEnrich) func(*testing.B)). Each helper drops the cognitive count of the enclosing function below the threshold without changing the test surface. - Don't: add
//nolint:gocognitto mask it. The threshold catches a real readability drift; helper extraction fixes both the lint and the readability. - Recurrence vector: any test/benchmark orchestration function that grows from 2 to 4+ dispatch arms inside a
for _, tc := range casesloop.
1.6 Wall-Clock Assertions and -race#
Race instrumentation multiplies execution cost, so a latency assertion calibrated without it measures the instrumentation. On a loaded machine TestPerformanceBaselines failed 10 of 10 runs under -race and passed 10 of 10 without it — one of the reasons the detector is local-only (§ 1.7).
- Rule: never add a wall-clock upper bound to a test without deciding what it does under
-race. - Pattern:
internal/testing/racedetect.Enabledis a build-tagged constant. Skip the assertion when the test is a latency baseline (TestPerformanceBaselines), or scale the bound when the bound is a coarse guard rather than a measurement (cancelAbortBudgetininternal/converter, which only needs to tell "aborted" apart from "generated the whole document"). - Subprocess builds: a test that shells out to
go buildgets no benefit from a-racerun (the child is not instrumented) and pays for it twice: the build cache holds only race-flavored artifacts, so the child compiles cold, and a deadline calibrated against a warm cache kills it.build_test.goskips underracedetect.Enabledfor exactly this reason. - Do not reach for
-shortto dodge this. It also skips the stress and thread-safety tests, which are the ones most worth running under the detector.
1.7 The Race Detector Is Local-Only, Deliberately#
just test-race runs the detector locally and is part of just ci-check. It is not a CI job, and adding one back is a regression, not an improvement.
GitHub's shared runners cannot host it reliably. The instrumented suite is slow and contended enough that the job fails without producing a usable signal — the last attempt exited non-zero after every one of the ~40 packages reported ok, with no data race, no failing test, and no error text anywhere in the log, then passed on a retry with no code change. A gate that red-lights a clean tree and greens a rerun teaches contributors to re-run it rather than to read it, which is worse than not having it.
- Where the protection actually comes from: the
forbidigorule in.golangci.ymlforbidst.Parallel()incmd/at lint time (§ 1.1), andjust ci-checkruns the detector before you push. - If you re-add the job, you must also re-add its Mergify gates.
.mergify.ymllistscheck-successconditions in three places (the dependabot queue, thedefaultqueue, and theFull CI must passrule). Removing a job without removing its gates deadlocks every PR on a check that never reports; adding a job without adding its gates means nothing enforces it. - The
-raceaccommodations in the test suite stay.internal/testing/racedetect.Enabledand the skips it drives (§ 1.6) exist for the local run and are still load-bearing. - The PR that removes a gated check cannot pass its own gate. Mergify evaluates
.mergify.ymlfrom the base branch, so a PR deleting a job is still judged againstmain's copy, which still requires it —Full CI must passsits at "Waiting checks:<job>" indefinitely. This is not a misconfiguration and cannot be fixed from inside the PR; a maintainer merges it manually, and every PR afterwards uses the new config. The repo already routes workflow changes this way: theAuto-queueprotection excludes any PR touching.github/workflows/.
2. Plugin Architecture#
2.1 Registry Independence#
audit.PluginManager owns its own PluginRegistry instance — there is no package-level global registry to opt into (the deprecated GetGlobalRegistry/RegisterGlobalPlugin/GetGlobalPlugin/ListGlobalPlugins singleton was removed; it had no production caller).
- Gotcha: Two
PluginManagerinstances constructed withNewPluginManager(logger, nil)each allocate a private registry and do not see each other's registrations. Pass the same*PluginRegistrytoNewPluginManagerwhen multiple managers or subsystems must observe the same plugin set. - Requirement: A dynamically loaded
.soplugin is registered by the loader through its exportedPluginsymbol into whichever*PluginRegistrythe caller supplied toNewPluginManager— there is no separate "global" registration step.
2.2 Panic Recovery Retains Plugins#
RunComplianceChecks wraps each plugin's RunChecks() in defer recover(). On panic, a dedicated recovery path populates PluginFindings, PluginInfo, and Compliance with safe defaults, then uses continue to skip further method calls on the potentially corrupt plugin.
- Gotcha: The recovery path must NOT call methods on the panicked plugin (
Name(),Version(),Description(),GetControls()) — the plugin's internal state may be corrupt after the panic. Instead, it uses thepluginNamestring already in scope and setsVersion: "unknown (panicked)"with an empty compliance map. - Invariant: Every selected plugin must appear in all result maps, even if it panicked.
2.3 SetPluginDir Must Precede InitializePlugins#
PluginManager.SetPluginDir(dir, explicit) configures the directory for dynamic .so loading. It must be called before InitializePlugins(ctx) because InitializePlugins reads pm.pluginDir only during its execution. Calling SetPluginDir after InitializePlugins mutates the field but has no observable effect on plugin loading because InitializePlugins has already completed.
2.4 Info Severity Does Not Bypass Compliance#
Reclassified info-severity controls (e.g., FIREWALL-003 "Message of the Day") participate in the compliance map normally — they can PASS or FAIL. Severity only affects presentation priority (summary counts, sort order), NOT compliance status. The compliance flip in RunComplianceChecks is never skipped based on severity.
- Gotcha: A finding with
Severity == "info"that references a control still flips that control to non-compliant. This is intentional — severity is triage priority, not compliance gating. - Gotcha: Inventory controls (
Type: constants.FindingTypeInventory) are excluded from theevaluatedsliceRunChecksreturns, so they never enter the compliance map. They only appear in "Configuration Notes." (This slice was historically calledEvaluatedControlIDs; that field no longer exists.) - Gotcha:
applyFindingsToComplianceskips inventory findings on an exactTypematch, andFinding.Typeis an unvalidated string supplied by the plugin. A finding mislabeled as inventory would exempt itself from the compliance flip, so the skip warns when an inventory-typed finding carrieshigh/criticalseverity, and warns again on anyTypethatconstants.IsValidFindingTypedoes not recognize. The exemption still applies — a plugin must not be able to change gate behavior — but it is no longer silent. - Gotcha:
countSeveritiestracks unrecognized severity strings in a privateunknowncounter. Callers with loggers should warn whencounts.unknown > 0.
2.5 Dynamic Plugin Trust Model#
PluginRegistry.LoadDynamicPlugins uses plugin.Open() to load .so files from a directory. Loaded plugins execute with full process privileges — there is no signature verification, checksum validation, or sandboxing.
- Gotcha: Any
.sofile in the plugin directory will be loaded and executed. A malicious or compromised plugin has the same access as the opnDossier process itself. - Mitigation: Loading is opt-in: it requires an explicit
--plugin-dirflag (or the equivalent config key). There is no./pluginsauto-discovery fallback —PluginManager.InitializePluginsonly callsLoadDynamicPluginswhenpluginDir != "". Plugins are never fetched remotely. - Prevention: Restrict filesystem permissions on the plugin directory. Only load plugins built from reviewed source code. In shared or CI environments, avoid pointing
--plugin-dirat world-writable directories.
Phase A hardening (v1.5). Before plugin.Open is invoked, runPluginPreflight in internal/audit/plugin_preflight.go rejects the following footguns and emits a structured audit log per attempt:
- Symlinks rejected via
os.Lstat+os.ModeSymlinkcheck.plugin.Openfollows links, so an attacker with write access to the plugin directory could otherwise point a.soat anything on the filesystem. - Non-regular files rejected via
info.Mode().IsRegular()(cross-platform). A FIFO, socket, or device node named*.sowould otherwise blockhashFileSizeCappedindefinitely onos.Openorio.CopyNbeforeplugin.Openis ever reached — a DoS primitive trivially reachable on POSIX. - Group/world-writable plugin files rejected when
info.Mode().Perm()&0o022 != 0(POSIX only). Closes CWE-732 where another local account could swap the file between audits. - Group/world-writable container directory rejected via a second
os.Statonfilepath.Dir(path)(POSIX only). The file bits alone are not enough — a writable parent lets an attacker unlink and replace the plugin. - Absolute plugin file paths required at preflight via
filepath.IsAbs(cross-platform, defense-in-depth). Relative--plugin-dirinputs from the operator are accepted and normalized viafilepath.Absbefore the preflight runs, so--plugin-dir ./pluginsis a supported invocation; the absolute-path check then fires if any caller ever bypassesLoadDynamicPluginsand hands a relative path directly torunPluginPreflight. - Structured audit log per load attempt: INFO for accepted loads, WARN for rejections, with fields
plugin,path,sha256,mode,owner_uid,mtime,size_bytes,verdict,reason. The loggedpathis the normalized absolute plugin artifact path, and the SHA-256 is computed with a 64 MiB read cap so a pathological.sobounds preflight I/O and CPU time (the hasher streams rather than buffers, so this is a time/throughput cap, not a memory-allocation cap).
Rejections are reported as PluginLoadError entries in the returned LoadResult, so callers see identical wiring for preflight and plugin.Open failures.
Phase B follow-ups (post-v1.5, tracked in todo #146): owner-UID check (refuse .so whose UID does not match the process UID or a configured allowlist), hard configurable size cap (--plugin-max-size-mb), path denylist (/tmp, /var/tmp, /dev/shm, $HOME when EUID==0), filename allowlist (no NUL / shell metachars / path separators), optional plugins.sha256 manifest enforcement, documented seccomp/landlock sandboxing recipe, and — aspirationally — out-of-process plugin isolation à la HashiCorp go-plugin.
Windows behaviour. POSIX permission bits are meaningless on NTFS, so the writable-mode and writable-dir rejections are skipped at runtime when runtime.GOOS == "windows". The symlink and absolute-path checks still run. The owner_uid audit field is emitted as unavailable on Windows; Phase B will introduce a SID-aware ownership check if needed.
See also: docs/solutions/runtime-errors/plugin-panic-recovery-audit-runchecks.md — fault-isolation pattern that contains panics from the untrusted plugins described here.
3. Data Processing#
3.1 Map Iteration Order#
Go map iteration is non-deterministic.
- Gotcha: Any CLI output or file export derived from a map (e.g.,
report.Compliance,report.Metadata) must be sorted before rendering. - Solution: Use
slices.Sorted(maps.Keys(m))orslices.SortFunc()to ensure deterministic, testable output.
3.2 XML Presence vs. Absence#
The encoding/xml package treats self-closing tags (e.g., <disabled/>) and missing tags identically for string fields.
- Gotcha: Use
*string(pointer to string) when you need to distinguish between "element present but empty" ("") and "element absent" (nil). - Instance (fixed): OPNsense before 26.1 and pfSense both test
<system><ipv6allow>withisset(). pfSense writes an enabled setting as an empty element and OPNsense shipped<ipv6allow/>as its default up to 24.1, but both schemas typed the fieldstringand both converters tested!= "". Every pfSense config with IPv6 allowed, and eight of the nine OPNsense fixtures that carry the element, read IPv6 as disabled, so FIREWALL-006 passed. Both fields are*stringnow and the converters test for non-nil.BoolFlagis not used here: it reads<ipv6allow>0</ipv6allow>as off, and for this field that misread makes FIREWALL-006 pass on a firewall that allows IPv6.
3.3 Repeated XML Elements and string Fields#
When an XML element appears multiple times (e.g., <priv>a</priv><priv>b</priv>), a string field only captures the last occurrence — all others are silently dropped. Use []string for elements that can repeat.
- Symptom: Only the last value is retained; no error is raised.
- Detection: Compare parsed struct against raw XML — earlier occurrences are silently overwritten by later ones. A quick sweep: walk each fixture in
testdata/and report every(parent, child)pair wherechildappears more than once under one parent instance, then check that the matching schema field is a slice. - Fix: Change the field type from
stringto[]stringwith the samexmltag. - Known instance (fixed):
<dnsserver>repeats once per resolver in both<system>and each<dhcpd><interface>scope.pfsense.System.DNSServerswas already[]string, butDHCPInterface.Dnsserverwas a scalar on both vendors, so every DHCP scope silently reported only its last resolver — including intestdata/pfsense/config-pfSense.xml, which configures two onlan,opt1andopt5. This reached the JSON/YAML export.common.DHCPScopegainedDNSServers(dhcp[].dnsServers, an array); the old scalarDNSServeris retained and deprecated per the public-API deprecation policy, andSetDNSServerskeeps it mirroring the first entry so the two cannot drift.TestParser_ConfigPfSense_DHCPScopesKeepEveryDNSServerguards the parse,TestDHCPScope_SetDNSServersthe invariant. - The two schemas drift apart, and the pfSense side is usually right.
pkg/schema/pfsensemodelledGroup.Member,Group.PrivandUser.Privas[]stringwhilepkg/schema/opnsensehad the first two asstringand omitted the third entirely, so the same three-member group read as one member on OPNsense and three on pfSense. When you touch a repeated element in one schema, diff it against its sibling: an asymmetry is either a real vendor difference or a bug, and it is nearly always a bug. - Known instance (fixed): the parent path can be wrong too. OPNsense stores port forwards as
<rule>directly under<nat>, with the redirect address in<target>, at every release checked from 15.1 to 26.7.Nat.Inboundwas bound asxml:"inbound>rule"and read<internalip>, a shape no release writes, so every OPNsense port forward was dropped: the report said none were configured, the red audit and FIREWALL-054 had nothing to check, anddiffnever saw one change (#877). The pfSense schema bound the right path all along, and its comments named the OPNsense shape as the difference. No OPNsense fixture had a port forward, and the converter tests builtschema.InboundRuleby hand, so nothing decoded through<nat>.testdata/opnsense-port-forwards.xmlandtestdata/opnsense-legacy-port-forwards.xmlcarry both generations of the rule body, andTestInboundRule_BindsEveryFixtureElementfails on an element the schema does not bind. - An MVC
ArrayFieldhas no container element. The model writes each item as the field's own name, repeated directly under its parent:<dnsmasq><hosts uuid="...">...</hosts><hosts uuid="...">...</hosts>. The legacy pages wrote the same shape.DNSMasq.HostsandDomainOverrideswere bound ashosts>hostanddomainoverrides>domainoverride, so each host override decoded as one empty{}entry (the<host>text child matched the item binding) and no domain override was ever read. Read the model XML fortype="ArrayField"before choosing a binding: the field name is the item tag. The same model also keeps dnsmasq's DHCP ranges and reservations, which reachCommonDevice.DHCPas scopes withSourcednsmasq; the 26.7.9 factory default serves LAN DHCP this way and has no<dhcpd>. Once the last entry is deleted the legacy pages leave a self-closing<hosts/>or<domainoverrides/>, which the four dnsmasq item types drop throughIsPlaceholder(see 3.4); a uuid alone does not make an item real, since the model loader skips any item without child elements. - A slice is not automatically safe — check what element it is bound to.
Sysctl []SysctlItemwithxml:"sysctl"tellsencoding/xmlthat<sysctl>itself repeats. The vendor instead writes one<sysctl>container holding repeated<item>children, so every tunable in the file collapsed into a single entry with emptyTunableandValue— 287 tunables across the shipped fixtures reduced to one blank row per file, and a config with no tunables decoded identically to a config with two hundred. Either bind through the container (xml:"sysctl>item") or give the slice its ownUnmarshalXML, asSysctlItemsdoes, when both the container and a legacy flat shape must decode. Watch for a scalar field that exists only to absorb the mis-parse: it is a sign the binding is wrong, not that the vendor writes a scalar there.SysctlItem.Itemwas exactly that, and was deleted once the binding was corrected — nothing could populate it any more, and leaving it would have kept the evidence of the bug in the public shape. - Writing an
UnmarshalXML? Check whether its siblings pair one. Every other custom container inpkg/schema/opnsense—Dhcpd,Interfaces,InterfaceList— definesMarshalXMLalongside.SysctlItemsshipped without one, so the encoder fell back to the default and emitted one<sysctl>element per tunable in the legacy flat shape instead of one container of<item>children. Nothing failed: the values round-tripped, because the unmarshaler accepts both shapes. The document simply stopped being what the vendor writes, andpkg/parser/opnsense/roundtrip_test.godoes not touch sysctl, so nothing noticed. A one-directional custom codec is worth a second look on its own — but the cheaper signal is the neighbours, since an unpaired type in a package where every sibling pairs is a stronger smell than the asymmetry read cold.GatewaysandGatewayModelItemare unpaired on purpose: theirUnmarshalXMLdecodes what the default decoder would and adds onlyGateway.HasChildElement, which is taggedxml:"-", so the default encoder still writes the fields the vendor wrote.TestGateway_HasChildElement_BothStoresmarshals with the field set and cleared to keep it that way. It cannot keep an item whose only children are empty or unbound, such as<name/>or<priority>: the encoder omits them, the item reads back as a placeholder, and a model holding only such items falls back to<gateways>on the second read. An alias embedded to reuse the default decoding needs an exported name: encoding/xml takes an embedded struct'sXMLNamewithout offsetting its index, so it reads the embedded field itself and panics when that field is unexported. - The value parsed correctly and still never appeared? That is a different failure with its own entry — see §3.6. Dumping the schema struct tells the two apart: a value missing from the dump was lost here, one present in the dump but absent from the export was lost at the converter. Reach for the sweep in §3.6 only after this one comes back clean, since a wrong binding hides a converter gap behind it.
3.4 Empty Placeholder Elements Become Phantom Entries#
OPNsense and pfSense write a self-closing placeholder inside a container when nothing of that type is configured — <staticroutes><route/></staticroutes>, <bridges><bridged/></bridges>, <ppps><ppp/></ppps>. The shipped DTD declares <!ELEMENT bridged EMPTY> for exactly this reason. Each placeholder unmarshals into a one-element slice holding a struct whose configuration fields are all zero — XMLName is populated, which is why most predicates below compare named fields rather than the zero value, and why the one that compares with the zero value, Rule.IsPlaceholder, clears XMLName first — so a converter that appends unconditionally produces a phantom entry in CommonDevice.
- Symptom: A firewall with none of the resource configured reports one.
opndossier convert testdata/sample.config.5.xml --format json | jq -c '{ppps, routes: .routing.staticRoutes}'returned{"ppps":[{}],"routes":[{}]}before the guards landed. - Impact is not just counting. Two consumers break in user-visible ways.
CommonDevice.HasRoutesis a has-data predicate that decides whether a report renders a routing section at all, so a phantom renders a routing section for a firewall that has no routing configuration.internal/diff/analyzer_routing.gocompareslen(StaticRoutes)for both its section-added guard and its"%d routes"count, so a phantom on one side alone reports a spurious route-count change. A third consumer,internal/analysis/unused.go, iterates the slice but is unharmed: it only callsaddRef(route.NetworkRef), andNamedObjects.Ref("")returns nil for a phantom's empty network, so no bogus reachability root is added. reflect.DeepEqualagainst the zero value cannot detect it. Every schema element type carriesXMLName xml.Name, whichencoding/xmlpopulates on unmarshal, so a decoded<ppp/>is never equal toPPP{}. A barereflect.DeepEqual(x, T{})silently never matches and becomes dead code;Rule.IsPlaceholdercompares with the zero value only after clearingXMLName.- Fix: guard at the converter boundary with a field-explicit predicate. Each guarded type carries an
IsPlaceholder()method inpkg/schema/opnsense; both parsers consume those same types, so one predicate serves every call site. Keep it conservative — drop an entry only when every configuration field is zero (XMLNameis excluded, since the decoder always sets it), so one carrying a description alone survives. Under-reporting configured resources is the more dangerous direction for an auditing tool. - Also drop the preallocation. A guarded loop may skip an append, so
make([]T, 0, len(src))violates the preallocation rule inAGENTS.md§ Mandatory Practices item 7. Usevar result []T— which also makes a placeholder-only container return nil rather than an empty slice. - Regression tests: the
*_IsPlaceholder_DecodedEmptyElement_ReportsPlaceholdertests inpkg/schema/opnsensefail loudly if theXMLNamepremise ever stops holding. The*_EndToEnd_PlaceholderNotCountedtests in both parser packages drive XML through parse and convert, which the struct-building converter tests never did — that gap is why this shipped undetected. - Adding a field to a guarded struct?
TestIsPlaceholder_EveryFieldDefeatsPlaceholder_NoFieldIsSilentlyUncovered(pkg/schema/opnsense/placeholder_test.go) sets each non-XMLNamefield in isolation and asserts the entry survives, so a field missing from a predicate fails there instead of silently dropping real config. It has no allowlist to drift, and a field type it cannot populate fails loudly rather than being skipped — extend the test and the predicate together. - These element types are guarded. Eight match every
EMPTYdeclarationtestdata/opnsense-config.dtdmakes for a repeated element:route,bridged,ppp,gif,gre,lagg,vip, andvlan. When adding a repeated-element container, grep that DTD for<!ELEMENT <name> EMPTY>— a hit means the vendor emits a placeholder and the converter needs a guard. Do not assume a container is clean because no phantom has been reported: the second five were found only because the first three were fixed and someone re-checked the DTD against the fixture. InboundRuleis guarded although the DTD does not declare it: the empty<rule/>OPNsense 18.7.10 to 25.7 leaves directly under<nat>once the last port forward is deleted (InboundRule.IsPlaceholder). The DTD lists only<outbound>under<nat>, so the grep above does not find it. Without the guard a firewall with no port forwards reports one, and FIREWALL-054 fails on it for having no description.TestConverter_PortForwards_EndToEnd_PlaceholderNotCountedcovers it.- The empty
<gateway_item/>is guarded too, because it can decide which store is read: the DTD declares it with required children, so the grep does not find it either. OPNsense skips it in the model from 24.1, whatever its attributes, and under<gateways>from 24.1.3, so a model holding nothing else falls back to the legacy gateways. Counted as a gateway, it would replace the real ones with a phantom, not just add one.convertGatewayItemsdrops it from both stores before choosing. pfSense'sgateway_itemis a list tag, asruleis below, so it is not guarded there. Comparing decoded fields is not enough here, because the vendor tests the element and not its values: both stores skip an item only when SimpleXML'scount()is 0, andcount()counts child elements and nothing else. An item whose only child is<name/>,<disabled>0</disabled>or an element the schema does not bind, such as<priority>, decodes to the zero value and is still a gateway, and in the model it makes the firewall ignore<gateways>.Gateways.UnmarshalXMLandGatewayModelItem.UnmarshalXMLrecord it inGateway.HasChildElement, and both predicates keep an item that has it; a value built in code has no record and is a placeholder when no field is set. Text, CDATA, comments, processing instructions and attributes, the uuid among them, do not count. A child with a namespace prefix is the one known difference:count()skips it and the decoder counts it, since it sees the prefix already resolved. OPNsense never writes one.Gatewayhas noUnmarshalXMLand must not get one:GatewayModelItemembeds it, so the method would be promoted and decode a model item without its uuid and its<disabled>.TestGateway_HasNoXMLCodecfails if one appears. The shared every-field test cannot take the model type, soTestGatewayModelItem_IsPlaceholder_EveryFieldDefeatsItstands in for it.TestGateway_HasChildElement_BothStorescovers the record,TestGateways_UnmarshalXML_MatchesTheDefaultDecoderthat the methods decode what encoding/xml would, andTestConverter_Gateways_EmptyItemsandTestConverter_Gateways_ChildrenThatDecodeToZerothe converter. - The filter model's
<rule>is guarded too, but not counted here. OPNsense never writes an empty one; its guard mirrors the loader skipping it.FirewallFilterRulehas noXMLName, so its predicate compares with the zero value instead of naming fields, and its own every-field test stands in for the shared one (§3.8). - The empty
<rule/>under<filter>is guarded too: OPNsense 18.7.10 to 26.1 leaves one once the last legacy rule is deleted (Rule.IsPlaceholder).firewall_rules.phpempties the list,Config::fromArraywrites an empty list as one childless element, and the loader reads that back as an empty list, so the firewall loads no rule from it. The page is gone from 26.7, but an upgraded config can still carry the element. The DTD requires content in<rule>, so a grep forEMPTYdoes not find it. Without the guard the element takes every default of §3.8 and reads as an enabled pass rule from any to any, which fails FIREWALL-022 and SANS-FW-002 among others. Do not testTypealone: the rule a port forward stored for itself up to 24.7 has no<type>and is a real pass rule. The predicate compares with the zero value throughreflect.DeepEqualinstead of naming fields, once it has clearedXMLNameand the non-nil empty slice an<interface/>child decodes to, and the shared every-field test covers it all the same. One shape only a hand edit writes is not a no-op on the firewall: on the releases whose loader was read, 25.7 to 26.7.8, a<rule/>directly before a rule with content becomes an empty array at the head of the list (Config::toArray), andfilter_core_rules_userregisters that as a pass rule from any to any. The guard drops it anyway, with a Medium conversion warning so the lost rule is not silent (warnOnLoadedPlaceholder);fromArraywrites the element only for an empty list, and a<rule/>after a real rule is a string the firewall skips.TestConverter_FilterRules_EndToEnd_PlaceholderNotCountedcovers these. - pfSense port forwards and filter rules are deliberately not guarded. pfSense's writer (
xmlparse.incdump_xml_config_sub) treatsruleas a list tag, so an empty list emits nothing: a box with no port forwards writes<nat></nat>and one with no filter rules<filter></filter>.<rule></rule>appears only when a list element is itself empty, which no pfSense page produces. The citations live onconvertInboundNATRulesandconvertFirewallRulesinpkg/parser/pfsense/converter_security.go. Decide a container is unguarded by reading the vendor's writer, as here, not by the absence of a reported phantom. If a vendor-written<rule/>ever surfaces from a real pfSense config, add the predicate, enrol it in the every-field test, and drop the preallocation.
3.5 "any" Has Four Spellings in the Common Model#
An endpoint that matches every host reaches common.RuleEndpoint.Address as any of four values, and a check comparing against one of them misses the rest:
"any"-- what the converters normalize<any/>,<any>1</any>and<network>any</network>to- any casing of it -- the vendor XML is not case-normalized
""-- an omitted or empty<source>/<destination>element; a rule with no source matches every source, andtestdata/gateway_groups_test.xmlcontains such a<rule>0.0.0.0/0and::/0-- what automation and hand-edited configs write
Use analysis.IsAnyEndpoint / analysis.IsAnyPort / analysis.IsAnyProtocol / analysis.IsWideOpenPassRule, never a bare == constants.NetworkAny. Reach for IsAnyEndpoint rather than IsAnyAddress whenever you hold a common.RuleEndpoint: the endpoint also carries Negated, and a negated 0.0.0.0/0 or ::/0 matches nothing rather than everything. A negated any is the exception: neither firewall inverts any, so the rule still matches every host, and FIREWALL-022 and FIREWALL-023 passed such a rule until #929. A negated endpoint with no address counts as any too: OPNsense reads it as any, and pfSense does not load the rule, so any is the conservative reading. A negated address list counts as any as well (§3.8). Sixteen sites across internal/plugins/{firewall,sans,stig} and internal/analysis/{detect,engine} had the bare comparison, so a WAN pass rule matching all traffic reported compliant on FIREWALL-022 and FIREWALL-023.
- Detection: build the same rule five ways (
any,ANY,"",0.0.0.0/0,::/0) and assert the check fires on all five.TestFirewallPlugin_AnyAnyPassRule_AllAnySpellingsis the pattern. - A port range has two spellings too. A rule port writes a range as
8000-8100; a port alias member can only write it as8000:8100, because the alias model validates withUtil::isPortand the ruleset loader withis_portrange, and both split on:. Either may also name a service, or a range of two names.parsePortPartreads numbers, both range forms, and the 50 service names of OPNsense's PortField, matched case-sensitively asgetservbynamedoes. An alias member may use only the 39 of those that FreeBSD's/etc/servicesalso carries, since that is whatgetservbynamereads. A member is read as one port or one colon range, and any other form, such as a dash range like20-25, a comma list orany, is left unknown. The vendors differ here. OPNsense's loader drops all three and keeps the other members. pfSense's (filter_generate_nested_alias_recurse) takes a dash range oranyfor a hostname, hands it to filterdns and then empties the whole alias, and what pf does with the emptied alias has not been checked. A comma list is not a hostname, so it is kept verbatim, and pf loads20,23as ports 20 and 23. Unknown is the reading both can share, andanyis not the any-port wildcard in a member. A readable member beside one of these still decides a control: an alias ofanyand23fails SANS-FW-015, which is right for OPNsense and errs toward reporting on pfSense. The shadow analysis and the SANS port controls never read a comma list in a rule's own port, whatever it holds: OPNsense disables the rule (Rule.phpL104-L123;Util::isPortsplits on:only), and pfSense writes no port statement, so the rule passes every port (filter_generate_port). Red mode's port correlation (RulePortPermits) still reads such a list as its ports, which under-reports on pfSense. Any other value, such assyslog, is unknown to it, not matching nothing: the shadow analysis reports the pair as blocked, so a pass over a block still surfaces as the R8 advisory. Only a dimension proven disjoint overrides that: two different single protocols, ports read in full, two literal addresses or networks with neither negated, or an address side where one rule negates a set and the other matches only inside it (complementDisjoint,sameInterfaceToken).addressRelationalso returns CoverNone for values it cannot compare, such aslan,(self), a hostname or a negated network, and that proves nothing. A pass to every port is an exception: every port covers the set whatever it holds, so the unread part cannot change the answer, and the pair is a confirmed shadow, not the advisory, when its other dimensions are covered. When one of them cannot be compared, the unread part counts again and the pair is the advisory, as it is when the pass names a port (TestDetectShadowedRules_AnyPortPassOverUnreadablePortAlias). A pair that negation leaves undetermined is the advisory too when part of it cannot be read; negation alone keeps a pair silent. The complement proof holds in three shapes only. Both sides name the same alias, which the firewall loads as one table whatever it holds. Both sides hold the same(self)or interface address token (lanip) of an interface the config defines, which every release checked writes as a single pf expression. An interface network such aslanis not one: OPNsense addsfe80::/10to it on an IPv6 rule before negating it, and OPNsense up to 17.1 and pfSense up to at least 2.6.0 write it as a braced list when the interface carries a virtual IP outside its subnet, and pf negates each entry of a list, so the negated copy matches every address. Or every value on both sides is a literal address or network read through enabled host and network aliases. That walk expands an alias named more than once, by one alias or through several, once and keeps each network once, and proves nothing past 16 levels of nesting, 4096 aliases or 4096 distinct networks (TestLiteralPrefixes_RepeatedAndSharedAliases,TestDetectShadowedRules_ComplementThroughRepeatedAliases). Against a different alias or a literal network, a disabled alias (it loads with no members), an exclusion member such as!10.1.0.0/16, an interface token, a hostname and a geoip, URL or external alias prove nothing. So!10.0.0.0/8against10.0.0.0/8,!(self)against(self)and!lanipagainstlanipare silent, while!lanagainstlanstays the advisory on every address family, as does any pair of hostnames, since a negated name with several records negates each one. A port set read in full that holds no port, from a disabled or empty alias, matches no traffic, so its rule takes part in no shadow either way.TestDetectShadowedRules_PortAliasVendorFormsdrives the alias member forms (a colon range, service names and a range of two names) through both parsers,TestParsePortPart_VendorFormspins each form, the rule-port dash ranges included, andTestCoverage_DisjointDimensionWinspins which dimensions count as proof. - A rule's port can be an alias name. Both converters keep the name in
Portand setPortRef, so a check that comparesPortwith"23"passes a WAN rule to an alias holding telnet. Read ports throughanalysis.EndpointPorts, which expands the alias as the loader does: nested aliases in turn, and a disabled one, at any depth, as no port at all. A member it cannot read, a cycle or a non-port alias leaves the set incomplete but keeps what it could read, so a check fails on a port that part names and is undecided only when it names none. An alias named twice by one alias is skipped the second time, and one named through several aliases is expanded once, a disabled or non-port alias included. The 4096-range member cap counts merged ranges, as OPNsense's loader keeps each port once, so repeating a name never pushes a set over it. Each parent still copies the ports of every alias it names, though, and those copies count toward the 1,048,576-range budget below, so an alias of 4000 separate ports named through 300 aliases reads as incomplete. An alias whose reading met a cycle, the depth cap or a budget is read again each time it is reached, and all three leave the set incomplete anyway: the walk leaves it incomplete past 16 levels of nesting, 4096 alias expansions or 1,048,576 gathered ranges (TestEndpointPorts_RepeatedAndSharedAliases,TestEndpointPorts_SharedLeafAlias,TestEndpointPorts_WorkBudget). When every alias sits above a cycle, none can be cached, and the expansion budget is what keeps the walk small, since the depth cap still lets the paths multiply at each level (TestEndpointPorts_VisitBudgetStopsCyclicFanOut). A rule with either endpoint read in full and holding no port matches no traffic, so the four controls skip it whatever the other endpoint holds. SANS-FW-014, SANS-FW-015, SANS-FW-017 and SANS-FW-020 do this; SANS-FW-016 still compares literals.TestSANSChecks_ResolvePortAliasescovers both stores and both vendors. - Deliberately not converted:
isBlockAllRuleandisTerminalDenyRuleindetect.goidentify default-deny rules, so widening them widens an exemption rather than a detection, andisBlockAllRulecarries a byte-for-byte legacy output contract.isAnyAddressSetinoverlap.goalso stays as-is: the overlap engine does real CIDR containment, where treating0.0.0.0/0as an unconditional wildcard would make it cover IPv6 targets it cannot match. - Test fixtures: hand-built
common.FirewallRulevalues that leaveSourceunset now read as "any source". Pin an explicit address when a test is about something else, or it will trip the permissive-rule detectors.
3.6 Values Parsed But Never Converted#
The schema and CommonDevice are separate models, and a value can be decoded correctly into the first yet never reach the second. Nothing errors, and the tests that exercise converters by building structs by hand never notice, because they only assert on the fields the converter already sets.
- Symptom: the value is present in
config.xmland in the parsed schema struct, absent from every output format.filter.rule.tagdecoded fine on pfSense and was simply never assigned;model.FirewallRulehad noTagfield at all whilemodel.NATRulehad one, so the mark-then-match pairs that implement egress policy read as unconditional rules. - Detection: extract every non-empty XML leaf value from a fixture, run
convert --format json, and report values that appear in the file but in no output. Separate the two layers by also comparing against a rawxml.Unmarshalinto the schema type — a value missing from the schema dump is a parse bug (§3.3), one present there but missing from the export is this. Expect false positives wherever the converter deliberately reshapes: aliases are split from10.0.0.1 10.0.0.2into amemberslist,system.timeserverslikewise, and secrets are excluded on purpose. - Fix: add the field to
pkg/modelif it is missing, then map it in both converters. The two are edited independently and drift, so fix the pair together. - Declared gaps are not this.
pfsense.KnownGaps()lists theCommonDevicesubsystems the pfSense converter knowingly leaves empty, and each emits a conversion warning. Check that list before treating an empty subsystem as a bug. - A value can reach the export and still decide nothing. Each port forward's
<natreflection>can turn reflection back on under a global<system><disablenatreflection>: OPNsense reflects a forward that ends up withpurenatorenable(ForwardRule.php), and pfSense'sfilter.increflectsenableandpurenatwhatever the global mode. Both converters exported the per-forward value, while FIREWALL-056, the NAT summary andsecurityFeaturesread the global flag alone, so a firewall that reflected a forward passed the control.NAT.ReflectionDisablednow holds only when reflection is off globally and no enabled, redirecting forward turns it back on; a global on is never disabled, even when every forward opts out, because the next forward added would reflect. Keep the global flag in that rule, and diff it on its own as well:CompareSystemdoes not compareSystem.DisableNATReflection, andnat.reflectionDisableddoes not move when the flag is toggled while an enabled, redirecting forward setspurenatorenable, so the NAT section reports the flag itself assystem.disableNatReflection. Removing forwards set todisableor to the default leaves both entries unchanged; removing the last reflected forward under a global disable movesnat.reflectionDisabled, as it should. The vendor default changed shape too, so read each release: up to 25.7 OPNsense filled it in witharray_merge, only for an absent element, and from 26.1 for any valueempty()accepts.System.DisableNATReflectionstays the global flag as written.TestConverter_NATReflection_PerForwardOverridein both parser packages andTestCompare_NATReflection_GlobalAndPerForwardcover it. - A value can also be dropped before it ever reaches the schema struct, one layer earlier than the usual case above.
internal/cfgparser/xml.go'shandleStartElementdispatches each top-level<opnsense>child through a hand-maintainedswitchthat mirrors thexml:tags onschema.OpnSenseDocument. It had no case foraliases, so a config using the legacy top-level<aliases>block (predating the MVC Firewall/Alias subsystem — seeschema.OpnSenseDocument.Aliases) decoded tonamedObjects: nulleven though the field existed on the schema struct and the converter (convertNamedObjectsinpkg/parser/opnsense/converter_aliases.go) already read it correctly. No shipped fixture used that shape, so nothing failed untiltestdata/opnsense-legacy-aliases.xmlwas added.- Guard:
TestHandleStartElement_DispatchCoversEverySchemaFieldininternal/cfgparser/dispatch_coverage_test.goparsesxml.goviago/ast, extracts every case label inhandleStartElement's switch together with thedoc.<Field>it decodes into, and reflects overschema.OpnSenseDocument'sxml:tags to assert a 1:1 pairing. It fails on a missing case (a new top-level element added to the schema with nothing dispatching it) and — checking the target, not just the label — on a case that decodes into the wrong field (a copy-paste swap between adjacent, structurally identical elements likegifs/gres/laggs, which a label-only check would miss). - When adding a new top-level
<opnsense>child element to the schema, add its dispatch case in the same change. The coverage test will fail the build if you forget; it will not tell you if you misroute one unless the swap changes which field is referenced in the case body.
- Guard:
- One struct can serve two sets of elements.
schema.Aliasis bound on the model path and on the legacy<aliases>block, and they do not write the same elements: the model writes<description>,<content>and<enabled>, and the legacy block writes<descr>,<address>,<url>and a repeated<aliasurl>. Only<descr>,<content>and<address>were bound, and the model aliases in the fixtures were hand-written with<descr>, so every test passed while a real config lost its descriptions, a legacyurltablealias had no members, and disabling an alias reported no changes, although OPNsense then loads most types empty and a block rule naming one stops matching. Write a fixture for a model from the vendor's model file, astestdata/opnsense-alias-model.xmlis, never from the schema: a fixture copied from the schema's tags can only agree with them.- Absent is not the same as 0 here. The alias table template reads a missing
<enabled>as 0, but the model's default is 1, OPNsense writes the element on every save, and a legacy or pfSense alias has none. So only a present 0 or empty element reads as disabled, and a config that merely gains the element reports nothing. - Disabled does not always mean empty, and empty does not always mean no match. A disabled alias loads with no members, so an endpoint naming it matches nothing. Its table is still declared, so an inverted endpoint matches every address, and a pass rule that inverts it opens up. The alias loader skips the
externalandinternaltypes (has_parserinalias_init.py), so disabling one of those leaves its table as it is.diffreports and rates that entry all the same, which overstates it in the safe direction. <expire>is not a fetch setting. Anexternalalias fetches nothing. The element purges unused addresses from its table (core.incrunspfctl -T expire), so lowering it on an alias a block rule names lets addresses through early. It is bound and rated for that reason, while<updatefreq>stays unbound.- The element the firewall loads can move between releases. On a legacy
urlalias OPNsense up to 17.7 loads<address>, where it kept what it last fetched. Aurl_portsalias loads it at the 17.1 tag and nothing from 17.1.11 through 17.7. From 18.1 both fetch<aliasurl>and ignore<address>(lib/alias.py,filter_core_get_url_port_alias). MigrationM1_0_0reads it the later way, and a member list taken from the migration alone hid a change the earlier releases load.aliasMemberskeeps every legacy source for that reason, so a config holding both reports a members change when it migrates. A vendor comment or migration describes one release: read the loader of each release the code path serves.
- Absent is not the same as 0 here. The alias table template reads a missing
3.7 A Newer OPNsense Release Can Delete the Element You Read#
An OPNsense migration can move a legacy element into an <OPNsense> model and delete the original, or raise a model's version and drop a field the new version no longer defines. A value opnDossier reads correctly on older configs then reads as unset on current ones, with no error and no warning.
- Instance (fixed): OPNsense 26.1 moved the IPv6, offload and VLAN filter settings from
<system>into<OPNsense><Interfaces><settings>(Interfaces/Migrations/SET1_0_0.php), turningipv6allowinto the inverteddisableipv6. On a migrated config all five fields read as off, so FIREWALL-006 passed on firewalls with IPv6 enabled.applyInterfaceSettingsreads the block now. OPNsense 26.1 and later read only the block, so it wins over anything left in<system>. Without the block the converter falls back to<system>, which is right for older configs but can disagree with a 26.1.0 config whose migration failed (a<dhcp6_norelease>yes</dhcp6_norelease>broke it until 26.1.1); OPNsense then treats IPv6 as allowed and offloading as on. - Instance (fixed): OPNsense 24.1 moved gateways from
<gateways><gateway_item>into<OPNsense><Gateways>(Routing/Migrations/M1_0_0.php) and deleted the originals, so a config whose gateways had migrated exported none.convertGatewayItemsreads the model when it holds a gateway and<gateways>otherwise, the rule the vendor'sgatewayIteratorfollows; a<gateway_item>with no child element does not count (§3.4). Legacy gateways left beside a model that holds one, as after a failed migration or a hand edit, are ignored with a Medium warning naming them, as the converter warns wherever it ignores something the config says (§3.6). Gateway groups stayed under<gateways>. The model writesdefaultgwandmonitor_disableas0where the 23.7 page left the element out, andcommon.Gatewaykeeps both as text, sogatewayFlagreduces them to1or empty for either store. Copied as they stand, every gateway that is not the default would export"defaultGw":"0". The stores read an absentmonitor_disabledifferently: the model defaults it to1, which turns monitoring off, andgatewayIteratorfills in0for a legacy gateway, soGateway.MonitorDisableis a pointer (§3.2).convertGatewaysfills inweightandipprotocolwhen they are empty, as current releases read them: the model defaults them to1andinet, OPNsense fills ininetfor a legacy gateway with an absent or emptyipprotocolfrom 20.1.7, and gateway groups read an empty weight as1from 19.7. Before those releases such a legacy gateway had no address family and an empty weight stayed empty, and the export showsinetand1for them too. The exception is an empty<ipprotocol/>in the model, which stays empty on the firewall and which opnDossier cannot tell from an absent one; OPNsense never writes one, as the field is required. The model's defaultinterfaceofwanis applied to a model item that leaves the element out, and not to a legacy gateway, to whichgatewayIteratorgives none. An empty<interface/>in the model stays empty on the firewall and reads aswanhere, the same approximation as foripprotocol, since the field is required and OPNsense never writes one.fargwgoes throughmodelFlagSetas well: the firewall tested it withisset()up to 24.1.7 and with!empty()from 24.1.8, and the two differ only on0and an empty element.disableddoes in the model only:GatewayModelItem.Disabledshadows theBoolFlagon the type pfSense shares with a*string. The firewall reads it with!empty(), which aBoolFlagreads the reverse of for an empty<disabled/>, and the pointer keeps an empty<disabled/>apart from an absent one, so that it is written back. Whether an item holding only<disabled>is a gateway is decided byGateway.HasChildElement(§3.4), not by this field. Under<gateways>it is still theBoolFlag, so hand-written text can read the reverse of the firewall's!empty(), as<disabled/>and<disabled>no</disabled>do. The model keeps its items by uuid, so of two with one uuid the firewall holds the later, at the place of the earlier, andmodelGatewaysdoes the same with a warning. An item with no uuid attribute gets a fresh one on every release. An empty uuid or0depends on the release: from 25.7 the loader testsempty(), which holds for both, and gives the item a fresh uuid, while through 25.1.12 it testsisset()and uses the attribute as the key, so two such items collide and the firewall holds the later. The model version is1.0.0on both sides, somodelGatewayskeeps both with a warning, which over-reports on the older releases.GatewayModelItem.UUIDis a pointer to keep absent apart from empty (§3.2). The uuid is onGatewayModelItemrather thanGatewaybecausegatewayIteratorignores one under<gateways>, and because an item with a uuid and no child element must stay a placeholder. - Instance (fixed): an element can outlive every reader. OPNsense core stopped running an SNMP agent at 17.1, the os-snmp plugin that went on reading the legacy top-level
<snmpd>was removed at 19.1, and os-net-snmp, which replaced it, reads only<OPNsense><netsnmp>. Every factory default up to 25.7 still wrote<snmpd><rocommunity>public</rocommunity></snmpd>, and nothing removes it, so most upgraded configs carry a block that no release starts an agent from: each agent that read it also required<snmpd><enable>, which the default never had. Read as live, the block failed FIREWALL-045, FIREWALL-046 and STIG V-206690 on firewalls with no agent, while, on a config without the legacy block, a net-snmp agent answeringpublicon WAN passed all three because its model was never read.convertSNMPreports net-snmp when its<enabled>is1, and otherwise a legacy block only when it carries<enable>, with a Low warning, since the config does not record whether the release still runs that agent. A plugin's model is not in the core tree: take its mount, versions and element names from the plugin repository, and take what an absent element means from the plugin's templates, which read the raw config, rather than from its model defaults. Consumers askSNMPConfig.IsEnabled()instead of testing the community, since an SNMPv3-only agent has none. Text that names community authentication still tests the community: red mode tells a WAN-exposed agent with none neither to migrate to SNMPv3 nor that it relies on a community. - Detection: for each OPNsense release, check what its migrations do to the elements the schema reads: a
post()that unsets a legacy path (src/opnsense/mvc/app/models/OPNsense/*/Migrations/), or a model whose<version>went up and whose field list lost or renamed a field, since the migration replaces the model's whole node. Test the migrated shape by rewriting a fixture the way the migration does, asTestConverter_InterfaceSettings_ReadFromMigratedBlockdoes, rather than generating XML from the schema. - A release can stop reading an element without any migration touching it. 20.1 dropped the remote server fields from the logging page and forwards only to
<OPNsense><Syslog><destinations>, but nothing moved or removed<syslog><remoteserver>,<enable>and the per-category flags, and the pages that still write<syslog>write single keys into the existing array. An upgraded config keeps them, so FIREWALL-039, FIREWALL-041, SANS-FW-004 and STIG V-206678 to V-206681 passed on a firewall with no remote target. 19.7 read both stores, so no element marks the change;convertSyslogreads the legacy keys only when the config has no Syslog model and warns when it ignores them. Retention moved later and differently: migration M1_0_2 (24.7) copies<preservelogs>and<maxfilesize>into the model'sgeneral, whichlog_archivereads from then on. A migration search finds the second move and misses the first, so read the release's own readers too, not only itsMigrationsfolder. - Pin the model version. The new block's element names belong to its model version, so the converter warns on a
versionattribute it does not recognize, as it does for Unbound. See §18.1 for the risk. - Instance (fixed): Unbound's service state. Unbound migration 1.0.5 (23.7) moved
<unbound><enable>and<dnssec>into<OPNsense><unboundplus><general>asenabledanddnssec, and 1.0.3 moveddnssecstripped("Harden DNSSEC Data") into<advanced>; each unsets the legacy key. The converter read only<unbound>, so every config written since 23.7 had Unbound off: FIREWALL-058 failed with DNSSEC on and FIREWALL-007 went unknown.readUnboundServiceFlagspicks the store by model version, not by which element holds a value, because from 1.0.5 on the firewall reads only the model: an absent<general><enabled>takes the model default, off, even when a stale<unbound><enable>survives beside it. The stores are also tested differently. Before 1.0.5unbound.inctestedenableanddnssecwithisset(), and before 1.0.3dnssecstrippedwith!empty(); the model'senabledis tested withisEmpty(), itsdnssecwith!empty(), and itsdnssecstrippedreachesunbound.confonly when it is1. Only a missing or malformedversionattribute falls back to content.TestConverter_Unbound_ServiceFlagsFollowModelVersiondrives each release shape through the parser.
3.8 OPNsense Keeps Firewall Rules in Two Stores#
OPNsense loads firewall rules from <filter><rule> and from the firewall filter model, <OPNsense><Firewall><Filter><rules><rule>. Up to 25.7 the second store was the optional "Firewall: Automation: Filter" page. In 26.1 it is a rules page of its own, "Rules [new]", beside the legacy pages. From 26.7 it is the rules page, and the factory default keeps its two LAN rules there and leaves <filter> empty. The schema bound <rules> as one string, so a default 26.7 config converted to no firewall rules: no warning, exit 0, and every check that looks for a risky rule passed for lack of input.
- The two stores spell one rule differently. The model has
enabled0 or 1 where the legacy rule has a<disabled>1</disabled>element, tested with!empty()(§15.0),actionfortype,descriptionfordescr, flatsource_net,source_notandsource_portfor the nested<source>, the protocol in upper case withanywritten out,statetypekeepforkeep state, ICMPv6 types as numbers, and service names such ashttpsas ports.convertFilterModelRuleturns all of them into the legacy spelling, because the checks compare strings: SANS-FW-007 looks for the wordstate, and FIREWALL-024 reads an absent protocol andanydifferently. A field added to that converter needs its vocabulary converted too.TestConverter_FilterRules_MigratedRuleReadsAsItsLegacyTwinholds a rule in both forms. - Absent is not empty. An element a rule leaves out takes the model's default: enabled, quick, pass, in, inet, keep state, any. Five elements read differently when empty:
<enabled/>is a disabled rule,<quick/>is not quick,<ipprotocol/>is no address family, and an empty<source_net/>or<destination_net/>matches any address and drops that side's port. The other elements read the same empty as absent, except<sequence/>: the firewall sorts an empty one ahead of every numbered rule, and opnDossier, which cannot tell it from an absent one, gives it the default 1. OPNsense never writes one.Enabled,Quick,IPProtocol,SourceNetandDestinationNetare pointers for that reason (§3.2). The factory default and third-party generators write reduced rules, so the defaults are not a corner case. A flag is set by anything but an empty element and0(modelFlagSet). That is the firewall's test, notshared.IsValueTrue(§15.0): the model writes only0and1, and for anything else the firewall's reading is the one to report. The legacy store has the same defaults for<direction>,<statetype>and<quick>(FilterRule.php:in,keep state, and quick unless floating), andconvertLegacyFirewallRulefills them too, so a rule reads alike in both stores anddiffacross a migration is quiet on them; before, the legacy side was converted blank, and the two factory defaults diffed as modified with identical text.convertLegacyFirewallRuleused to make every non-floating legacy rule quick whatever<quick>held, and read<floating/>as not floating. The firewall applies the quick default only when the element is absent and reads a present one with!empty(), so<quick>0</quick>, which the legacy rules page writes for an unticked box, and<quick/>compile as not quick, a word such asnocompiles as quick, and an empty<floating/>is floating (#976).Rule.QuickandRule.Floatingare*stringnow:legacyQuickapplies the default on nil andmodelFlagSetto a present element, and<floating>is tested for presence, as the pfSense schema already did.TestConverter_FilterRules_LegacyQuickElementdrives each<quick>shape through the shadow analysis;TestConverter_FilterRules_LegacyFloatingElementpins presence, rank and the quick default on the converted rule. - A missing
<type>has a default too.FilterRule.phpreads it aspass, andconvertLegacyFirewallRulefills it in with the defaults above. pfSense'sfilter.inchas the defaults for<type>and, only on a rule that compiles as pass,<statetype>, and the pfSenseconvertFirewallRulesfills them: the rule its port forward page writes has neither, and a blank state type on a TCP pass rule fails SANS-FW-007 and SANS-FW-024. - Order is not document order. OPNsense sorts the model's rules by
<sequence>and breaks ties by uuid, with PHP's natural, case-insensitive comparison (naturalCompareFold). The key keeps the sequence as stored and pads it on the left when PHP'sis_numericaccepts it and on the right otherwise (modelRuleSortKey), so+100or100sort as they do on the firewall. Ties are ordinary: 24.1 to 25.1.4 gave every rule sequence 1 unless the operator typed another, and before 25.1.5 and again from 26.7.7 a cloned rule keeps its original's sequence, so the uuids decide which of the two comes first. - The firewall evaluates rules by rank. Floating rules come first, then rules on an interface group, by the group's
<ifgroups>sequence, then rules on one interface, and last the model's rules on no interface the config defines, or received on none, which it does not load. Within a rank the model's rules come before the legacy ones.filterRulesInOrderreproduces that (modelRulePriority,legacyRulePriority), and the index of a rule indevice.FirewallRulesis its place in that order. The model finds a group by the interface's<type>, the legacy store by<ifgroups>, so a rule on the built-inopenvpngroup ranks as a group rule only in the model. - Earlier releases rank the model differently. That rank order is 26.7.2's. The os-firewall plugin, up to 23.7, and the core on 24.1 and 24.1.1 put every rule of the model before every legacy rule: a list of interfaces, then a group, then the rest, where a rule with no interface did not float. Only the plugin wrote model versions 1.0.0 to 1.0.2 (1.0.2 on 23.7), and a migration raises the version on upgrade, so a config at one of them is ordered the plugin's way (
pluginRulePriority). The shadow analysis follows that order: it takes an OPNsense rule list as it stands and moves floating rules ahead of interface rules on any other device, because the pfSense converter keeps document order (floatingFirst).enrichtypes an untyped device as OPNsense, so only a direct analysis call makes the move on one. The core releases share versions: 1.0.3 covers 24.1 to 24.1.8, and 1.0.4 runs from 24.1.9 into 26.1. Before 26.1 a rule withinterfacenot, or with an empty entry in its interface list, ranked differently, and before 26.7.2 a rule on no defined interface kept its place. A config at a core version is therefore ordered as 26.7.2 orders it. - Floating is derived. The model has no
<floating>element. A rule floats unless it names exactly one interface and leavesinterfacenotunset, and a rule that names none applies on every interface (Floatingwith noInterfaces). A rule withinterfacenotapplies on every interface but the one it names; the common rule cannot say that, so it lists the others, with a warning, leaving out a group that holds the excluded interface, and a rule left with none is reported on every interface (Floatingwith noInterfaces), since the firewall applies it on each interface it does not name, lo0 and the tunnels among them. A list with an empty entry is reported as floating, since the firewall then also applies it on every interface, but it ranks by its other entries. For the legacy store the firewall tests for the<floating>element withisset()(filter.lib.inc), soyes,1and an empty element all float;Rule.Floatingis a*stringand the converter and the ordering test it for presence. - An address can be a list.
source_netanddestination_netcan hold several entries separated by commas.RuleEndpoint.Addressholds the list,AddressRefstays nil, andAddressRefsnames each alias in it, which the unused-object roots read (§23.3). Every other consumer still readsAddressas one value, so a list without negation is never "any" and never contained by a network. For that reason a list of the filter model that holdsanyor an empty entry, or without negation a wildcard network, is reported asanywith a warning, because that is what it matches; the aliases it names keep their references. A negated list keeps the list andNegated, with a warning: the firewall negates each entry on its own, so the rule matches every address outside the entries' overlap, which is every address when they do not overlap. The shadow analysis readsNegatedand does not rely on such a rule, and the checks for wide-open rules read it as any (analysis.IsAnyEndpoint), so neither errs in the unsafe direction. A list in a legacy<address>gets the references and nothing else, and a list on a NAT rule gets none. - The placeholder guard compares with the zero value.
FirewallFilterRulehas noXMLName, soIsPlaceholderis a comparison with the zero value once the uuid is cleared; OPNsense skips a<rule>with no child element whatever its attributes. A kept placeholder would be worse here than in §3.4: every default applies, and the result is an enabled pass rule from any to any on every interface. The comparison is on content, so a rule whose only children are empty elements of string fields, or elements the type does not bind, is dropped too, although OPNsense loads it; no release writes one. - A uuid can repeat. OPNsense keeps the model's rules by uuid, so of two rules with one uuid it loads the later; the earlier is left out with a warning. A rule under
<filter>with the same uuid is a different matter: the migration assistant copies rules into the model under their uuids and leaves the originals until the operator removes them, and the firewall loads both. Both are converted.diffpairs the copies by content first and then in list order (sameUUIDPairer), so adding a copy that differs from its original is not read as an edit to the original.--detect-ordernames the second copyuuid=...,copy=1and numbers the new side's copies by the same pairing, so when two copies swap places each is reported as moved. - The model version is pinned, which catches less than it seems. The converter warns when the model holds rules under a
versionit has not been checked against (knownFilterModelVersions, as §3.7 asks). Up to 1.0.6 each version only added rule elements, but OPNsense also adds elements without raising the version (auditarrived under 1.0.6), and the warning does not see those;TestFirewallFilterRule_BindsEveryFixtureElementdoes, once a fixture carries them. A version that renames<rules>or<rule>decodes to no rules, the §18.1 case, so an unrecognized version with no rules warns too, at Low. - Some elements are read but not reported.
received-on,tos,prioandmax-pkt-rate-numbernarrow what a rule matches,schedlimits when it applies, anddivert-toandreplytochange where the traffic goes. The common rule has no field for them, so each one set draws a Medium warning (unrepresentedRuleElements,checkReceivedOn, §3.6); the received-on warning followsreceived-on-not, and an empty entry in the list matches traffic from any interface. A packet rate counts only with bothmax-pkt-rate-numberandmax-pkt-rate-secondsset, as on the firewall. The other elements without a field, such asmax,max-src-states,overload,set-prio,shaper1andshaper2, are dropped without one, as the legacy schema drops them. - Still unread:
snatrules,nptandonetoonein the same model. They are bound as strings, nothing in them is decoded, and nothing warns when they hold rules. - Regression tests:
TestParser_FilterRulesFixtureand theTestConverter_FilterRules_*tables inpkg/parser/opnsense,TestNaturalCompareFoldandTestModelRuleSortKeyfor the tie-break,TestFirewallFilterRule_IsPlaceholder_EveryElementDefeatsItfor the guard, andTestFirewallFilterRule_BindsEveryFixtureElement, which fails when the fixture carries an element the type does not bind. The completeness check does not look inside an element that repeats.
3.9 A Rule With No Type Is a Pass Rule#
Both firewalls load a filter rule with no <type> as pass (filter.inc L3367-L3370, FilterRule.php parseType), and the rule pfSense adds for a port forward never has one. Both converters fill the type in (§3.8), so a rule reaches the analysis with no type only from a hand-built CommonDevice or a parser that does not fill it; effectiveRuleType guards that path. A comparison of FirewallRule.Type as it stands reads the empty string as a third action: a pass above such a rule was reported as "Security Deny Bypassed" with no deny in the pair, and such a rule above a block stayed troubleshooting.
- Classify through
effectiveRuleType.impactClassForand the finding's description do, on the confirmed and the advisory path. RulesEquivalentcomparesFirewallRule.Typeas it stands. A rule that reaches it with no type is therefore not a duplicate of a pass rule inDetectDeadRules, and a rule a converter filled in can be.TestDetectDeadRules_EmptyTypeKeepsLegacyOutputpins the first.- No other check uses it. Every comparison with
RuleTypePassoutsideimpactClassForskips a rule that reaches it with no type, includingIsWideOpenPassRule,DetectSecurityIssues, the compliance plugins, the red audit'swanRulePermitsPortand diff'sisPermissiveRule(#951). - Only the empty type is mapped. The pfSense converter already reports any type other than
pass,block,rejectandmatchas pass (§5.2). OPNsense hands the value to pf as written, which does not load the rule, so the analysis keeps the stored value and a pair holding such a rule stays troubleshooting. The GUI does not write one. - A
matchrule is not a deny. The pfSense GUI writesmatchon floating rules and the rule decides no traffic, soimpactClassForreturns Security only for a pass over a block or reject, on the confirmed and the advisory path. A pass over amatchrule, which loses its queue or tag, is troubleshooting.derivePairWinnerLoserstill lets a non-quickmatchrule win a pair, although pf never stops at one, so a block listed above it can be reported as shadowed by it, at troubleshooting.
4. Diff Engine#
4.1 Section-Level Added/Removed Guards#
Most Compare* methods in internal/diff/analyzer.go have early-return guards that emit a single ChangeAdded or ChangeRemoved when one side has data and the other does not. For pointer types (*common.System), this uses nil checks. For value types (NATConfig, slices), this uses HasData() or len() == 0. New Compare* methods must follow this pattern.
- Exceptions:
CompareFirewallRules,CompareUsersandCompareAliasesintentionally omit section-level guards because per-item granularity is more useful for security-sensitive resources (individual rule additions/removals are reported separately).
4.2 Rule and User Equality Helpers Must Cover Every Model Field#
rulesEqual and usersEqual in internal/diff decide whether a paired item is reported as modified. A field missing from either helper does not produce a weaker diff entry -- it produces no entry at all, silently.
Both had drifted badly: rulesEqual compared 7 of common.FirewallRule's 33 fields and usersEqual 5 of common.User's 7 (the denominators are now 35 and 8, after Tag/Tagged and Privileges landed; the guards forced the equality helpers to cover them, which is the point). A diff stayed silent on a rule's direction being reversed, a rule becoming floating or quick, its gateway being redirected, its state type weakened, its logging turned off, and on a user's UID changing or an API credential being added, rotated or removed.
- When you add a field to
common.FirewallRuleorcommon.User, add it to the equality helper.TestRulesEqual_ComparesEveryFirewallRuleFieldandTestUsersEqual_ComparesEveryUserFieldwalk the struct reflectively and fail until you do. - Only identity fields belong on the ignore list.
UUIDandTrackerare excluded becauseCompareFirewallRulespairs on them; comparing them would mark every paired rule modified. - Compare endpoints with
endpointsEqual, never==.common.RuleEndpointholds its alias references as pointers, soa.Source == b.Sourcecompared the pointers and was false for two parses of the same rule whenever an endpoint named an alias. SinceAddressRefsthe struct holds a slice, and==on it no longer compiles.rulesEqual,natRulesEqualandinboundNATRulesEqualall did this, and a config diffed against itself reported each such rule as modified, with identical old and new values. The per-field guards could not see it: they started from zero values, whose references are nil, and only asserted that a changed field is noticed, never that equal content compares equal. They now also fill two values separately and require them equal, andTestCompare_TwoParsesOfOneConfig_ProduceNoChangediffs each shipped config against a second parse of itself.
4.3 Most Configs Have No Rule UUIDs#
CompareFirewallRules pairs rules by UUID, but pfSense never writes one, and neither do older OPNsense configs -- 13 of the 17 XML fixtures under testdata/ have none on a firewall rule. The fallback used to compare only the rule count, so any content change that left the count intact was invisible: on testdata/pfsense/config-2.6.x.xml, flipping a rule from pass to block reported "No changes detected".
compareRulesWithoutUUID now pairs in three passes -- by pfSense's <tracker>, then by exact content (which anchors the unchanged rules), then by remaining position. Whatever is left unpaired is a genuine addition or removal.
- Do not "simplify" this back to positional pairing. The content-anchoring pass is what stops a rule inserted at the top from cascading into every rule below it reading as modified.
TestCompareFirewallRules_NoUUID_InsertionDoesNotCascadeguards it. - Test new comparison logic against a UUID-less fixture. A test built on
sample.config.6.xml(which has UUIDs) exercises a different code path than one built on any pfSense fixture. - Two known limits, pinned by
TestCompareFirewallRules_KnownLimits. Neither is a regression -- the count-only fallback reported nothing for either -- but both are sharp enough that a future change should decide about them rather than discover them:- A pure reorder produces no entry from content comparison. That is by design -- order changes are the order detector's job, reached via
--detect-order. Note that detector had the same UUID dependency:extractRuleUUIDsdropped every rule without a<uuid>, so--detect-orderwas a documented flag that silently found nothing on pfSense. It now keys onruleIdentity(UUID, else<tracker>), and rules with neither stay out because a rule indistinguishable from its peers cannot be said to have moved. - Leftovers pair by similarity, not position. Once the tracker and content passes have anchored what they can, the rest are scored against each other (
ruleSimilarity) and matched best-first. Blind positional pairing misattributed edits: witha, b, c(pass)becominga, c(block)it handed the survivingctoband reported "b modified into c" plus "c removed". Weights are description 4, interface list 2, and one each for type, protocol, source, destination and port;simMinScoreis 4, reachable by a matching description alone or by a matching interface list plus two other fields. AbovesimMaxPairsleftovers on either side the scoring is skipped and pairing falls back to positional, so a config where nothing anchors stays bounded.
- A pure reorder produces no entry from content comparison. That is by design -- order changes are the order detector's job, reached via
4.4 NAT Rules Were Compared By Count Only#
CompareNAT compared len(old.OutboundRules) != len(newCfg.OutboundRules) and the same for InboundRules, and nothing else. Every content change that left the counts intact was invisible: an outbound rule retargeted or moved to another interface, and -- worse -- a port forward redirected to a different internal host, which is about the most consequential NAT change there is.
No outbound NAT rule in any shipped fixture carries a uuid, and neither does a port forward from pfSense or from OPNsense before 26.1, so this is the path most real configs take. Port forwards saved by OPNsense 26.1 or later do carry one (testdata/opnsense-port-forwards.xml) and pair by identity.
- Rules now pair via
itemPairer(internal/diff/pairing.go): identity, then exact content, then similarity, with a positional fallback. the same pairer the firewall rules use. natRulesEqualandinboundNATRulesEqualmust cover every model field. A field missing from either produces no diff entry at all, not a less detailed one.TestNATRulesEqual_ComparesEveryFieldandTestInboundNATRulesEqual_ComparesEveryFieldwalk the structs reflectively and fail until you add it.- Paths are
nat.inbound.rules[N]andnat.outbound.rules[N]. Thenat.inboundprefix is load-bearing: the security scorer'sport-forward-changepattern matches on it, so renaming the path silently drops the impact rating from every port-forward entry.
4.5 The Displayed Text Is Not What Was Compared#
A Change carries OldValue and NewValue for display. For most entries they are the one setting that was compared. For four they are not: a firewall rule, an outbound NAT rule and a port forward are shown as a one-line summary of a few fields (formatRule, formatNATRule, formatInboundNATRule), and a modified user has no value at all. The equality helpers of §4.2 and §4.4 compare every field but the identity ones (UUID, and Tracker on firewall rules), so a real change to a field the summary omits yields an entry whose two values are identical.
--normalize used to drop a modified entry whenever its two values were equal after normalization. Every entry of those four kinds whose change was outside the summary went: a rule that lost its logging, a redirected gateway, a reversed direction, any change to a user. With nothing else changed the command printed "No changes detected".
- Those four kinds are marked
summarizedand are never skipped. Requiring the raw values to differ is not enough for them. The whitespace normalizer runs over the whole summary, so whitespace at the end of one, such as a trailing space in a pfSense port forward's target, which ends its summary, made the two summaries differ before normalization and match after it, and the entry went together with the redirected port behind it.formattingOnlyholds the rule andTestFormattingOnlypins each clause.TestEngine_Compare_Normalize_KeepsChangesTheTextDoesNotShowandTestEngine_Compare_Normalize_KeepsChangeBehindSummaryWhitespacecover the kinds. - An alias's members are marked
summarizedtoo. The values show the members joined by,, and OPNsense keeps the spacing inside a<content>line, soa banda bread the same once whitespace is collapsed.TestEngine_Compare_Normalize_KeepsAliasMemberChangecovers it. Neither parser yields a member with a space at either end, so only the inside of a member can differ this way. - A new entry whose values leave out something that was compared must set
summarized. Nothing enforces it. An unmarked entry with identical values is still kept, because the skip also requires the raw values to differ, but one whose summaries differ by whitespace alone is dropped. - The cost: a formatting-only edit to one of those four kinds, or to an alias's members, is reported with the flag. A doubled space in a rule description, or a port forward's
<local-port>rewritten from8080to08080, is a modified entry with the same text on both sides. Both used to be hidden. - Do not decide anything else on the displayed text. A filter, a deduplication or a severity rule that reads
OldValueandNewValuesees less than the comparison did. Adding a field to a summary does not change that: nothing ties the summaries to the equality helpers, and a user entry cannot show an API key secret. - The normalizers see the whole displayed string. Whitespace is collapsed in any value, a summary included. The address normalizer acts only on a value that is an address or a CIDR by itself, so leading zeros inside a rule summary, a DHCP range or a list of several DNS servers are never normalized. Nothing else is normalized. A port normalizer used to strip leading zeros from any digits-only value, and from any
A-BorA:Bvalue with all-digit halves, so a hostname of007and one of7, or a description of2024-01and2024-1, normalized to the same text and the change was dropped (#882). It was removed rather than scoped to port fields: no non-summarized entry displays a bare port, since every port the diff shows sits inside a firewall rule or NAT summary or in an alias's members, all of them summarized, and a modified summarized entry is never skipped. An entry that displays a bare port must bring its own path-scoped normalizer and a test; until one exists, a leading-zero difference in a port is reported rather than hidden, which is the safe direction for an auditing tool. A zero-padded IPv4 octet is never normalized anywhere:172.016.000.001is 172.14.0.1 to aninet_aton-family parser and is rejected by Go'snet.ParseIPand byvalidate, soNormalizeIPreturns it unchanged and the change is reported with the value as written (#918). What is canonicalized is IPv6, where an IPv4-mapped literal such as::ffff:10.0.0.1prints as its dotted quad, and the CIDR prefix length.
5. CLI Flag Wiring#
5.1 Silent Flag Ignores#
A CLI flag can be accepted by Cobra, stored in a package-level variable, and silently ignored if the command handler never transfers it to Options or stores it in an untyped map no consumer reads.
- Symptom: Flag accepted without error but output identical with/without it.
- Detection: A new flag that breaks zero golden files or tests is likely broken.
- Prevention: Typed
Optionsfields (notCustomFields), regression tests per command, diff output with/without flag. - Reference:
docs/solutions/logic-errors/cli-flag-wiring-silent-ignore.md
5.2 Enum Type Casts from XML#
When converting XML schema string fields to typed enums (e.g., common.FirewallRuleType(rule.Type)), always validate with IsValid() after the cast and emit a conversion warning for unrecognized values via c.addWarning(). The DeviceType enum with ParseDeviceType() + IsValid() is the canonical pattern. Bare casts silently pass invalid values through the entire pipeline.
- Symptom: Invalid enum values (e.g.,
FirewallRuleType("match")) pass through the pipeline without error, failing silently in downstreamswitchstatements. - Prevention: Call
IsValid()after every XML-to-enum cast. ForNATOutboundMode,LAGGProtocol, andVIPModethere is no downstream validation — the converter cast is the only defense. - pfSense rule types are the exception.
filter.inccompiles any type other thanpass,block,rejectandmatchaspass, so the pfSenseruleTypereports such a value aspasswith a Medium warning instead of keeping it.matchstays as stored, with the Low warning, because the model has no value for it. The comparison trims tab, newline and carriage return first, ascDatainxmlparse.incdoes, and not spaces, which survive there, so a wrapped<type>reads as what it holds. OPNsense'sparseType(FilterRule.php) defaults only a valueempty()accepts, so an empty element and0read as pass. It hands any other value to pf as written, and pf does not load it, so that converter keeps the value. - Regression tests:
TestConverter_EnumCast_EmitsWarninginpkg/parser/opnsense/converter_enum_cast_test.goandpkg/parser/pfsense/converter_enum_cast_test.gocover every known callsite. When adding a new enum cast, add a row to the table-driven test in the same PR — otherwise the §5.2 defense is invisible. - History: The NATS-145 audit (2026-04-18) discovered two unguarded
IPProtocolcasts in OPNsenseconvertOutboundNATRulesandconvertInboundNATRulesthat had been silently passing invalid values through for months. Both were fixed in the same audit with the canonicalif field != "" && !cast.IsValid() { addWarning }pattern.
See also: docs/solutions/logic-errors/opnsense-nat-ipprotocol-enum-cast-missing-guard.md — full postmortem of the NATS-145 bare-cast audit, including regression-test patterns for new enum callsites.
5.3 PreRunE Test Commands Must Bind to Real Globals#
When testing PreRunE with a temporary cobra.Command, bind its flags to the same package-level variables the real command uses (e.g., tempCmd.Flags().StringVar(&auditMode, ...)). If you bind to local variables instead, PreRunE reads stale globals and tests pass vacuously. Always set values via cmd.Flags().Set() (not direct assignment) to exercise real pflag parsing.
6. Validator#
6.1 GID/UID Zero is Valid#
Unix GID 0 (wheel/root group) and UID 0 (root user) are valid. The validator check is gid < 0 / uid < 0, correctly allowing zero. Error messages must say "non-negative integer", not "positive integer".
See also: docs/solutions/architecture-issues/file-split-refactor-gotchas.md — the validator file-split refactor where this "non-negative integer" fix was applied alongside pre-existing helper issues.
7. Parser Registry#
7.1 Blank Import Requirement#
pkg/parser/factory.go dispatches through the registry, not via direct imports. The OPNsense parser only registers itself when its package init() runs, which requires a blank import: _ "github.com/EvilBit-Labs/opnDossier/pkg/parser/opnsense".
- Symptom:
"unsupported device type: root element <opnsense> is not recognized; supported: (none registered -- ensure parser packages are imported)"-- empty registry with hint - Cause: Missing blank import means
init()never ran, registry is empty - Fix: Add the blank import to the test file or production file using
parser.NewFactory() - Detection: Any new test file using
parser.NewFactory()that sees an empty registry is missing the blank import
See also: docs/solutions/architecture-issues/pluggable-deviceparser-registry-pattern.md — the registry pattern whose init-time self-registration is what the blank import activates.
8. Audit Command#
8.1 Mode/Plugin Coupling#
Only blue mode runs RunComplianceChecks. Red mode ignores SelectedPlugins entirely. The --plugins flag is rejected in PreRunE unless --mode blue is set.
- Gotcha: Adding plugin support to red mode requires wiring
RunComplianceChecksintogenerateRedReportinmode_controller.goAND removing the--plugins+non-blue-mode rejection guard incmd/audit.goPreRunE. - Gotcha:
--pluginsaccepts any name at the CLI level — validation is deferred toValidateModeConfigpost-init, which checks against the livePluginRegistry. Dynamic plugins loaded via--plugin-dirare included automatically when--pluginsis omitted (the "all available" default).
See also: docs/solutions/logic-errors/cli-prerun-validation-timing-dynamic-plugins.md — why plugin-name validation moved from PreRunE to post-init and how dynamic .so plugins now pass the CLI parse gate.
8.2 Concurrent Generation, Serial Emission#
runAudit in cmd/audit.go processes files concurrently via generateAuditOutput (returns string, no I/O), then writes results serially via emitAuditResult in the parent goroutine.
- Gotcha: Never add stdout writes or file exports inside
generateAuditOutput— all emission must go throughemitAuditResultto prevent interleaved output. - Gotcha:
--outputis rejected with multiple input files inPreRunEto prevent file clobbering.
8.3 Multi-File Output Path Uniqueness#
derivePerInputOutputPath uses lossless tilde-based escaping: tildes in path segments become ~~ and underscores become ~u, freeing the literal underscore to serve as an unambiguous directory separator. This prevents distinct paths from collapsing to the same filename, including boundary cases where one segment ends with _ and the next begins with _ (e.g., a_/b/config.xml → a~u_b_config-audit.md versus a/_b/config.xml → a_~ub_config-audit.md).
- Gotcha: Simple character replacement (e.g.,
/→-) is NOT sufficient — paths likea-b/c/config.xmlanda/b-c/config.xmlwould collide. The escaping must be lossless (invertible). The earlier double-underscore scheme (_→__, separator →_) was also insufficient — it collapsed at segment boundaries where trailing/leading underscores were indistinguishable from the separator. - Gotcha: Both
auditandconvertderive per-input paths from this one helper, and thesuffixargument is what keeps them apart.auditpassesauditOutputSuffix(-audit),convertpasses"". Dropping the suffix would make an audit and a convert of the same input write to the same filename. - Gotcha: Neither command may fall back to stdout for a multi-file run. Markdown and text concatenate readably, but two JSON documents produce
}{and fail to parse, two HTML documents give two doctypes, and two YAML documents without separators parse as one mapping where the later keys silently replace the earlier ones. - Gotcha: Expected output filenames are asserted in 5+ test functions (
TestDeriveAuditOutputPath,TestEmitAuditResult_MultiFileAutoNaming,TestEmitAuditResult_MultiFileConfigOutputFileIgnored,TestDeriveAuditOutputPath_BasenameCollision,TestDeriveAuditOutputPath_BoundaryUnderscoreCollision, etc.). When changing the encoding scheme, grep for all assertion sites — missing one causes CI failure.
8.4 Red Mode Analysis (formerly Stub Implementations)#
generateRedReport in mode_controller.go runs analysis.ScanObservations once, then its five analysis methods — addWANExposedServices, addWeakNATRules, addAdminPortals, addAttackSurfaces, addEnumerationData (implemented in internal/audit/red_analysis.go) — perform real, reachability-filtered analysis of the CommonDevice. The former placeholder-stub behavior and the cmd/audit.go PreRunE "experimental / not yet implemented" warning were removed in the red-lens slice (epic #281, slice 2).
- Findings vs. metadata split: Only three of the five methods append to
report.Findings.addWANExposedServices(the primary producer: one Finding +AttackSurfaceper WAN-reachable WebGUI/SSH/SNMP service),addWeakNATRules(WAN-reachable inbound NAT port-forwards), andaddAttackSurfaces(WAN-reachable shared-engine hygiene observations reframed as exposure, de-duped byComponent).addAdminPortalsandaddEnumerationDataemit structured metadata only (portal inventory tagged by reachability; recon counts) — deliberately NOT Findings, to avoid double-counting an exposure already surfaced by a Finding-producing method. Every WAN exposure still lands in Findings, but via the method that owns that exposure class: firewall-local management-service exposure (WebGUI/SSH/SNMP) viaaddWANExposedServices, and inbound NAT port-forward exposure independently viaaddWeakNATRules. The metadata-only methods never introduce an exposure that one of those two does not already surface as a Finding. - WAN-exposed = correlation, not enabled-alone: a firewall-local management service (WebGUI/SSH/SNMP) is WAN-reachable only when enabled AND a WAN-reachable firewall pass rule permits its port (
wanRulePermitsPort/analysis.RulePortPermits, which the security score'shasManagementOnWANshares). Port matching biases to over-report (empty/any/ranges/lists match by containment; an unresolvable port alias is treated as permitting — never under-report a possible exposure). - A WAN is not an interface named
wan: OPNsense gives only the first uplink thewankey, and every further one keeps theoptNkey the assignments page gave it, so a key test alone read a second uplink as LAN-only and passed FIREWALL-023, FIREWALL-029 and FIREWALL-030 on it. A rule or port forward on an interface group applies on every member (filter.incifgroup_setup), but the key test read the group's own name, so a group withwanamong its members read as LAN-only unless its name happened to start withwan.analysis.IsWANInterfacetakes the device for that reason: it expands a group listed indevice.InterfaceGroupsto its members, so the members decide and the name does not. An interface is an uplink on thewankey prefix, on the two signals the vendors' own interface-gateway test uses (dynamic addressing, or a<gateway>/<gatewayv6>other thannone), and on one of opnDossier's own: an enabled gateway on it with its per-gateway default flag set, which pfSense from 2.4.5 does not write. The vendors resolve the selection differently. OPNsense ignores one that names a gateway on another interface (getInterfaceGateway), so on OPNsense only a gateway on that interface or a name the config does not define counts; pfSense resolves the name among every gateway, so any name counts there, and so does it on a device of no known type. A static gateway on an inside interface that is not the default does not count. A LAN that is itself a DHCP client does, as it does on the firewall, which reply-to's its traffic and NATs onto it. The entry OPNsense writes under<interfaces>for each group (virtual, typegroup) is never an uplink, whatever its name. Every check of whether a rule, port forward or interface faces the WAN, the security score's management check included, goes throughRuleReachability,InterfaceReachabilityorInboundNATRuleReachability; do not classify WAN-ness by comparing an interface name withwan. A vendor rule that is itself tied to thewankey, such as where the anti-lockout rule is placed, is a different question and may name the key. - NAT rules never correlate against firewall-local services:
wanRulePermitsPort(used only byserviceReachabilityfor WebGUI/SSH/SNMP) deliberately never countsdevice.NAT.InboundRulesas exposure. An inbound NAT rule forwards WAN traffic toInboundNATRule.InternalIP, normally a different host than the firewall itself, so a NAT rule sharing an external port with a management service is never evidence that the firewall's OWN service is exposed. A forward can target the firewall, but the evidence is then the filter rule that passes it, never the forward. An earlier version correlated NAT rules here too, producing a false positive: a NAT rule forwarding WAN port 22 to an unrelated internal host's SSH would flag the firewall's own SSH daemon (also on port 22) as WAN-exposed even with no pass rule ever targeting the firewall directly. NAT-forward exposure is reported separately and correctly byaddWeakNATRules. SeeTestRedMode_NATForward_DoesNotExposeFirewallLocalService. The filter rule a port forward stores for itself does not count either: pf matches it after rdr, against the forward's target, sowanRulePermitsPortskips a rule whose destination is a forward'sInternalIPwhen that target is a literal address or network holding no loopback address, interface address, DHCP alias address or virtual IP (forwardsToAnotherHost). The destination is the whole test, so it covers the same rule with no link, as OPNsense's "Add unassociated filter rule" wrote it up to 25.7, andAssociatedRuleIDis not read: from 26.1 deleting a forward leaves its rule behind with the link, so a link alone proves nothing. A network that holds one of those addresses keeps the rule, since traffic to that address passes the rule too, so a forward to a directly attached network still reads as exposing the service. A rule to an alias is skipped when a forward targets that alias, since both vendors copy an alias target onto the rule as it stands, unless a member of the alias, or of an alias it names, is or spans one of those addresses (aliasHoldsFirewallAddress). That walk readsMembersdirectly rather than throughResolve, which stops on a network group (§23.1). The members the config holds are the only evidence: an alias whose members are fetched at runtime, such as a URL table, has none to test and is skipped, and a hostname with a domain tells nothing. A wildcard network such as192.168.0.1/0.0.255.0is read bit by bit, as OPNsense'snet_wildcard_iteratorexpands it. A name no alias defines keeps the rule, both as a<target>and as a member of a host, network or network group alias (namesUnstoredTable). OPNsense generates__lan_network, which holds the firewall's own address, and static tables such asbogons, and writes none of them toconfig.xml, so such a member can hold anything. A hostname with no domain has the same shape and is over-reported the same way. The inbound rules can only take a rule away there, never add one. A rule of its own to an address, network or alias no forward targets still counts, since the firewall may hold an address the config does not record, such as a DHCP lease. An address the config records anywhere but on an interface or as a virtual IP, such as a tunnel's inner address, is not read, so a forward to it reads as one to another host. pfSense virtual IPs are not converted yet (pfsense.KnownGaps), so on pfSense a forward to a CARP or IP alias address reads the same way. A forward that stores no filter rule (the Pass association, which pf gets asrdr pass, and on the 26.1 model<pass>set topassorrule) giveswanRulePermitsPortnothing to read, so one to the firewall's own address reports no exposure at all. - A port forward can keep a loopback SNMP agent's verdict: the bullet above holds for
wanRulePermitsPort, but one step outside it readsdevice.NAT.InboundRulestoo. An os-net-snmp agent bound only to loopback is set Local after every other step (applySNMPListen), unless an enabled forward that can redirect UDP port 161 targets a loopback address or a network or range spanning one,(self)(This Firewall, which pf reads as every address of every interface, those oflo0included), an alias that may hold one, the net or address of an interface whose own address is a loopback address, such aslo0, or a name no alias or interface defines that has the shape of an alias name (forwardsToLoopback). pf rewrites a forward's destination before the packet is delivered, so such a forward can reach an agent bound to loopback. An alias that may hold one includes a URL alias, a URL table, a URL table in JSON format and an external alias, whose addresses OPNsense gets at runtime, a host alias holding a hostname, which OPNsense resolves through DNS when it loads the alias (resolvedThroughDNS), and an alias naming one at any depth (aliasNamesRuntimeTable). The read above treats such an alias the other way, as holding no address of the firewall, andaliasHoldsFirewallAddresskeeps that reading for it. The net or address of any other interface, such aslanorlanip, does not count: pf redirects such a forward to that interface's network or address, where the agent does not listen. That reading of a target is the oneForwardRule.phpapplies from 26.1.2. Through 26.1.1 it maps a target only when an alias of that name exists, of any type, and disables a forward to any other name that is no address or network as an invalid target,(self)and interface names among them, so on those releases a forward to(self), or tolo0when no alias has that name, keeps the verdict although it redirects nothing, which over-reports. The forward never makes the agent reachable by itself: it only keeps the agent from being set Local, and the agent keeps the reachability the earlier steps gave it. Neither the forward's interface, nor<system><disablefilter>, nor whether the target's address family is one the agent listens on is read there, so a LAN forward (TestSNMPAgent_ForwardInterfaceIsNotRead), a forward on a firewall with packet filtering off, or a forward to::1for an agent bound to127.0.0.1keeps the verdict too, which over-reports. The key andipform is matched for every interface, although OPNsense maps it only for wan, lan and optN and disables a forward to any other such name no alias defines as an invalid target, so a forward tolo0ipkeeps the verdict too, which also over-reports. Do not removeforwardsToLoopbackas a regression of the bullet above: without it, a WAN forward of UDP 161 to loopback with the rule that passes it reports no exposure, andTestSNMPAgent_PortForwardToLoopbackKeepsWANExposurefails. - Web GUI port comes from the unified model, not a hardcode:
common.WebGUI.Portcarries the configured web-configurator port. Both the OPNsense and pfSense parsers populate it from<system><webgui><port>when the element is present inconfig.xml; the 443/80 protocol default applies only when the configured port is absent (either vendor). Red analysis readsdevice.System.WebGUI.PortviaparsePortrather than assuming 443/80, so a box on a custom GUI port is analyzed correctly regardless of vendor. New device parsers should populate this field when the platform exposes a GUI port. - Rules describe nothing when packet filtering is disabled: this and the anti-lockout rule below are the two exceptions to the correlation rule above: either one makes a management service WAN-reachable with no pass rule in
FirewallRules.<system><disablefilter>makes both vendors runpfctl -dand return before any ruleset loads (filter.inc, tested withisset(), so an empty element counts), so no rule, block option, NAT or anti-lockout rule applies and every service is reachable from every interface. A check that readsFirewallRulesalone passes such a box.System.PacketFilterDisabledcarries the setting: the shared engine raises a critical WAN-reachable finding, red mode marks every management service WAN-reachable (markImplicitWANExposure), and each compliance plugin fails the controls listed in itspacketFilterControlsthroughcompliance.FailWhenPacketFilterDisabled. A new control whose pass verdict means the firewall restricts, inspects, logs or translates traffic belongs in that list, and in the listTestPacketFilterControls_Listpins in the plugin's package: an end-to-end run cannot pin it, because the fixtures fail several of these controls on their own checks. Only SANS-FW-016 is held back: it joins the list only when the config holds an FTP port forward, and otherwise stays Unknown. Every other listed control fails even where its own check would report Unknown, so on a config without the inputs those checks need, SANS-FW-007, -017, -021 and -024 go from Unknown to Fail. Port forwards are still reported byaddWeakNATRulesalthough pf performs none, which over-reports. - The anti-lockout rule is a WAN pass rule on a firewall with no LAN or OPT interface: unless
<system><webgui><noantilockout>is set (tested withisset()), both vendors add a quick pass rule to the web GUI port and, with SSH enabled, the SSH port, ahead of every user rule and absent fromFirewallRules. OPNsense 22.7.5 and later put it on the first of thelan,optNandwankeys, enabled or not, so the WAN gets it when nolanoroptNkey exists, which is what the console's WAN-only assignment writes. OPNsense up to 22.7.4 tooklanoropt1when it had a device, and otherwisewanwhen it was the only enabled interface. Both read the interfaces with virtual entries left out, so loopback and the VPN groups count for neither rule. pfSense takeswanonly when it is the only interface.antiLockoutOnWANreads the rule as on the WAN when any of these would put it there, the safe direction, except that the 22.7.4 rule is not applied to pfSense, and not when thewaninterface is disabled or has no device. Only thewankey counts as the WAN here, so a rule the firewall places on anoptNthat is itself an uplink is not reported. On pfSense the SSH port is covered only in principle: pfSense writes<ssh><enable>, which the schema does not read, so SSH reads as off there. - ExploitNotes safety: red
ExploitNotescarry impact/context only (never weaponized/step-by-step guidance). Enforced byFindInstructionalContent(exploit_notes_safety.go) run over the actual generated notes plus a golden-file gate — not authoring discipline.--audit-blackhatselects the sharper-tone variant (red mode only; rejected inPreRunEfor blue mode) and adjusts tone only — the denylist safety invariant holds for both tone variants. - NAT correlation is an intentional over-report: an inbound NAT rule is treated as WAN-reachable when any enabled WAN pass rule exists (not one correlated by port to that specific forward). This is a deliberate safe-direction choice — precise per-rule correlation would risk under-reporting a real exposure, the wrong failure mode for a security audit.
9. Dupl Linter Bidirectional Firing#
9.1 Cross-Type Validator Duplication#
When adding device-specific validators that are structurally similar to existing validators (e.g., validatePfSenseSystem vs validateSystem), the dupl linter fires on BOTH files — not just the new one.
- Gotcha: Adding
//nolint:duplonly to the new function is insufficient. The existing function also needs//nolint:duplbecauseduplreports pairs. - Pattern: Both sides of the duplicate pair must carry the suppression directive.
9.2 Validator Cascade on Document Field Type Forks#
When changing a Document field type from an opnsense type to a local pfSense fork (e.g., opnsense.Dhcpd → pfsense.Dhcpd), the pfSense-specific validator function that accepts a pointer to that type will fail to compile. The shared field-level validator (e.g., validateDhcpdInterface) still expects opnsense.DhcpdInterface, so the pfSense wrapper must construct a temporary adapter value.
- Symptom:
cannot use &doc.Dhcpd (value of type *pfsense.Dhcpd) as *opnsense.Dhcpd - Fix: Update the pfSense validator signature to accept
*pfsense.Dhcpdand adapt each item toopnsense.DhcpdInterfaceinside the loop before calling the shared validator. - Also update: Test files (
pfsense_test.go,parser_test.go) that constructopnsense.Dhcpd{Items: map[string]opnsense.DhcpdInterface{...}}— change topfsense.Dhcpd/pfsense.DhcpdInterface.
10. Converter Testing#
10.1 TerminalDisplay Output Is ANSI-Rendered#
TerminalDisplay.Display() (internal/display/display.go), reached from cmd/display.go and cmd/audit_output.go, passes markdown through glamour.Render(), which inserts ANSI escape codes. Tests asserting on the output must set t.Setenv("TERM", "dumb") for clean text. Since t.Setenv is incompatible with t.Parallel(), remove t.Parallel() and add //nolint:tparallel to the function.
- Symptom:
assert.Contains(t, out, "System Configuration")fails despite the text being present. - Fix: Add
t.Setenv("TERM", "dumb")at the start of the test (not.Parallel()). - Precedent:
internal/display/display_test.gouses this pattern throughout. - History: this entry previously named
MarkdownConverter.ToMarkdown, a secondglamour.Rendercaller ininternal/converterdeleted as superseded dead code (refactor/dead-surface-cleanup).internal/displaywas always the other caller and inherits the same requirement.
10.2 builder_test.go Uses Raw testing Package#
internal/converter/builder/builder_test.go does not import testify/assert. Use strings.Contains + t.Errorf for assertions, not assert.Contains.
- Symptom:
undefined: assertcompilation error in builder tests. - Detection: Check imports at top of test file before adding new test functions.
10.3 NAT Rule Field Name Disambiguation#
NATRule.Target is the NAT translation target address. InboundNATRule.InternalIP is the port-forward destination — there is no Target field on InboundNATRule. The outbound type is named NATRule, not OutboundNATRule; only NATRule and InboundNATRule exist, so an earlier version of this entry named a type that never did.
Tag and Tagged are on both FirewallRule and NATRule. This entry previously said FirewallRule had neither, which was a description of the bug rather than of the model: the fields were missing until the converters stopped dropping them (§3.6).
10.4 Never Return md.String() or buf.String() Raw#
github.com/nao1215/markdown emits the host's line ending — its internal.LineFeed returns "\r\n" on Windows and "\n" everywhere else. Any function that returns md.String(), or the bytes.Buffer/strings.Builder a markdown.Markdown was built into, therefore produces CRLF on a Windows checkout. That breaks every LF golden fixture and contradicts the LF guarantee in internal/export.
- Rule: in
internal/converter/builder, returnrenderMarkdown(md). Anywhere else, wrap the exit informatters.NormalizeToLF. Any new code path that constructs markdown independently of the builder needs the same treatment — the builder's helper does not protect an exit it does not own. glamour.Renderis not affected — it re-renders and emits LF, sointernal/display'sTerminalDisplay.Display()(§10.1) was already clean. Do not add a redundant normalization there.- Detection:
TestReportOutputIsLF(builder) asserts the invariant across the public output surface, but it can only fail on Windows. The Windows CI job runs the full suite for this reason. - CRLF on disk is still available via
OPNDOSSIER_PLATFORM_LINE_ENDINGS=1, handled ininternal/exportat write time.
10.5 Audit Metadata Values That Are Structs Render as Subsections#
ComplianceResults.Metadata is map[string]any, and writeAuditMetadata used to pass every value to formatters.EscapeTableContent, whose fallback is fmt.Sprintf("%v", ...). Five of the values are structs or lists of structs, so the blue report showed configuration_summary as {54 51 51 1} and recommendations as one cell of about 8,500 characters, and the red report showed enumeration_data as {54 1 51 0 1 1} and admin_portals as [{webgui 443 lan}] (#949, #990). Every format built from the markdown was affected: markdown, text, HTML and the terminal view. JSON and YAML never were, because the types carry tags.
- A struct or a list of structs gets a subsection of its own after the key/value table (
internal/converter/builder/builder_audit_metadata.go). A struct becomes a Field/Value table and a list of structs a table with one column per field, both labeled by reflection from the Go field names (InboundNATRulesreads as "Inbound NAT Rules"), so a structured key added later is labeled without a renderer of its own.[]audit.Recommendationis the one special case: each record carries a list, which no table cell can hold, so it renders as one bullet per component with the recommendations as a nested list. A[]stringstays in the table, joined with a comma and a space. - A value that implements
fmt.Stringerstays a scalar, so atime.Timeis not taken apart into fields. A list whose element type implements it, such as[]time.Time, stays in the key/value table too, joined as text; classified as a list of structs it rendered as a table with no columns, sincetime.Timehas no exported field. - The text format renders nested lists itself.
StripMarkdownFormattinghands lists to html2text, which gives every<li>the same-prefix whatever its depth, so the recommendations came out as one flat list. A list holding a nested list is now extracted into a placeholder like a table and rendered byrenderListBlock, two spaces of indent per level, with any text an item carries after its nested list on its own line at the item's indentation. Its placeholder is restored aftertrimLineWhitespaceruns, since the trim would strip that indentation; a table or alert placeholder inside such a list is restored in a second pass after it.TestStripMarkdownFormatting_AuditRecommendationsdrives the builder's output through the text pipeline. - The builder imports
internal/auditfor that type switch.internal/auditmust not import the builder, and neither may one of its tests, or the two form a cycle. - Regression tests:
TestBuildAuditSection_StructuredMetadataRendersLabeledin the builder andTestAuditMetadata_StructuredValuesRenderLabeledincmd, which runs both modes over a fixture and fails when the%vform of any struct-shaped metadata value appears in the output. That%vcheck is reflective and names no key, so a new structured key is covered by it without a test change; the heading assertions beside it do name keys and cover only the known ones.
11. Sanitizer#
11.1 pfSense bcrypt-hash Field Name#
pfSense stores user passwords in <bcrypt-hash> elements, not <password> or <passwd> like OPNsense. The sanitizer's field-pattern matching must explicitly include bcrypt-hash and sha512-hash — the generic "pass" substring match does not cover these.
- Symptom:
sanitizecommand outputs bcrypt hashes in cleartext. - Fix: Add
"bcrypt-hash","sha512-hash"to thepasswordrule'sFieldPatternsininternal/sanitizer/rules.go. - Precedent: The SNMP community string (
rocommunity) required a dedicated field pattern for the same reason.
11.2 New Device Type Field Names#
When adding a new device type (e.g., pfSense), audit the XML element names for credential fields that differ from OPNsense. The sanitizer operates on raw XML element names, not CommonDevice field names. Any device-specific naming for secrets must be added to the sanitizer's pattern lists.
- Detection:
sanitize <config.xml> | grep -i 'hash\|secret\|key\|pass'— check for unredacted sensitive values. - Prevention: When adding a new device schema, grep for credential-like fields and verify each is matched by a sanitizer rule.
11.3 OpenVPN TLS and StaticKeys Are Credentials, Not Labels#
OpenVPN's <tls> element (under <openvpn-server> / <openvpn-client>) holds the --tls-auth / --tls-crypt HMAC key, and the MVC <OpenVPN><StaticKeys> element holds static-key material. Both arrive in a PEM-shaped envelope with the literal label -----BEGIN OpenVPN Static key V1----- — which the stock IsPrivateKey detector misses because the label is not PRIVATE KEY. The sanitizer's private_key rule uses path-anchored FieldPatterns (openvpn.tls, openvpn-server.tls, openvpn-client.tls, openvpn.statickeys, statickeys, tls_crypt, tls_auth) plus the IsOpenVPNStaticKey envelope detector to catch both the field-name and value-based paths.
-
Gotcha: The substring
tlsALONE is not safe as a pattern. It would false-positive on:- The Suricata IDS wrapper
opnsense.OPNsense.IDS.general.eveLog.tls.*(a struct of enable/extended/sessionResumption/custom booleans —pkg/schema/opnsense/security.goL383). - The IPsec strongSwan daemon log-level enum
opnsense.OPNsense.IPsec.charon.syslog.daemon.tls(an integer 0–5 —pkg/schema/opnsense/security.goL443).
Always anchor OpenVPN TLS patterns to their parent element path (e.g.,
openvpn-server.tls) and verify new unambiguous OpenVPN field names (liketls_crypt/tls_auth) never collide with other device schemas before adding them bare. - The Suricata IDS wrapper
-
Detection:
TestSanitizeXML_OpenVPNStaticKey+TestSanitizeXML_OpenVPN_TLS_NoFalsePositivesininternal/sanitizer/sanitizer_test.go.TestIsOpenVPNStaticKeyinpatterns_test.gocovers the envelope detector. -
Rule-ordering impact: None. The
private_keyrule is distinct fromauthserver_config/password/email/hostnameand does not participate in the §19.1 ordering invariants. -
History: SEC-H1 from the 2026-04-19 comprehensive review. Prior to the fix,
opndossier sanitizesilently leaked raw HMAC keys sufficient to forge OpenVPN handshakes — the headline promise of the subcommand.
11.4 NetBird setupKey Is a Credential#
The OPNsense os-netbird plugin persists the NetBird enrollment/setup key as <setupKey> under <OPNsense><netbird><authentication> (MVC model mounted at //OPNsense/netbird/authentication). The value is a UUID-format registration token. Because the sanitizer's bare "key" FieldPattern is exact-match only (see exactMatchPatterns — same trap as SNMPv3 <enckey>), compound names like setupKey leaked through sanitize in cleartext.
- Symptom:
sanitizeleaves NetBird setup keys readable in output. The key remains inconfig.xmlwhen NetBird is disabled and often survives plugin removal as orphaned MVC XML, so disabled/removed plugins still leak. - Fix: Add
"setupkey","setup_key","setup-key"to thesecretrule'sFieldPatternsininternal/sanitizer/rules.go(enrollment token, not private-key material — unlike SNMPv3enckeywhich lives onprivate_key). - Detection:
TestSanitizeXML_NetBirdSetupKey_RedactsSecret+TestSanitizeXML_NetBirdSetupKey_NoFalsePositivesininternal/sanitizer/sanitizer_test.go;TestRedact_NetBirdSetupKey_RedactsSecretinrules_fieldpattern_test.go. - Rule-ordering impact: None. The
secretrule already precedesprivate_keyand does not participate in the §19.1 ordering invariants. - Upstream: https://github.com/opnsense/plugins (
security/netbird); field declared inAuthentication.xmlasUpdateOnlyTextFieldwith UUID mask. - History: Reported as a cleartext leak through
sanitizewhen NetBird is disabled or the plugin XML remains after removal; fixed in #728.
12. Git Tagging#
12.1 Tag the Squash-Merge Commit on Main#
When tagging a release after a squash-merge PR, always tag the resulting commit on main, not the PR branch head. Squash-merge creates a new commit on main that is not an ancestor of the branch commits. If you tag the branch head instead, the tag points to an orphaned commit that git log main and git describe will never reach.
- Symptom:
git tag --merged maindoes not list the release tag;git describeonmainskips the version. - Fix:
git checkout main && git pull && git tag vX.Y.Z && git push origin vX.Y.Z - Prevention: Always switch to
mainand pull before tagging. Never tag from the feature branch after merge.
13. Serialization Testing#
13.1 Multiline Secret Assertions Against Serialized Output#
assert.NotContains(t, jsonStr, rawPEMKey) is ineffective for multiline secrets: encoding/json escapes embedded newlines as \n, and yaml.v3 may emit block scalars with indentation. The raw PEM substring will often not appear even when the secret is fully present in the output.
- Symptom: Test passes even when redaction is broken — the raw multiline string never matches the encoded form.
- Fix: Unmarshal JSON/YAML output back into a typed struct and assert on the parsed
PrivateKeyfield values directly. - Precedent:
TestPrepareForExport_RedactsSensitiveFields_JSONininternal/converter/enrichment_test.godemonstrates the assertion shape — it checks the typedexported.Certificates[0].PrivateKeyfield rather than substring-matching the marshalled JSON, then separately confirms the output still parses. Note its fixture is a single-line placeholder, so it does not itself exercise the newline-escaping trap; when you add coverage for a genuinely multiline secret, use a real PEM block so the encoded form differs from the raw one.
14. Sanitizer Rule Engine#
14.1 ShouldRedactField Scans ALL Rules Globally#
ShouldRedactField checks field names against FieldPatterns from every rule, not just the rule being tested. Adding a FieldPattern to any rule can break "should not match" test assertions for other rules.
- Symptom: A new field pattern causes unrelated sanitizer tests to fail.
- Fix: Check all rules'
FieldPatternswhen adding new patterns. Test assertions must account for global matching.
14.2 Value Detector Ordering#
ShouldRedactValue checks field-name rules first (ShouldRedactField), then value-detector rules. Rules with both FieldPatterns and ValueDetector: a field match triggers redaction immediately; the value detector only runs on the value-only matching path.
14.3 Deterministic Mapper in Tests#
A fresh NewRuleEngine creates a fresh NewMapper() — mappings are deterministic (e.g., first private IP maps to [REDACTED-PRIVATE-IP-1], first hostname to host-001.example.com). Always assert exact expected values, not just inequality.
14.4 SanitizeStruct Skips Struct/Pointer-Valued Maps#
sanitizeReflect in internal/sanitizer/sanitizer.go cannot recurse into map[K]struct{...} or map[K]*struct{...} values. Map values are not addressable in Go, so reflect.Value.SetMapIndex is the only way to write back — and that requires a fully reconstructed element, which the current walker does not perform. The guard at the top of the reflect.Map case detects this and logs a warning via the optional logger injected through Sanitizer.SetLogger. When no logger is set, the gap is silent.
- Current scope: This gap is reachable ONLY through
SanitizeStruct, which is an opt-in consumer flow. The defaultopndossier sanitizeCLI usesSanitizeXML(raw element walk) and is not affected — element names like<password>and<bcrypt-hash>are still redacted regardless of the Go model shape. - Known current paths: OPNsense
KeaDhcp4already uses map-style subnet containers, but those maps hold config metadata, not credentials. No currently-shipped schema path puts a secret behind a struct-valued map. - Why warn instead of fix: Supporting struct-valued maps via reflection requires reconstructing each element in place (read → recurse into a copy →
SetMapIndexwith the mutated copy). That work is scheduled under todo #151 (tag-based redaction) which will subsume this gap by annotating sensitive fields directly and driving redaction from tags instead of field-name heuristics. The warning is the bridge until #151 lands. - Regression tests:
TestSanitizeStruct_MapStructValues_WarnsAndSkipsandTestSanitizeStruct_MapStructValues_NilLoggerNoPanicininternal/sanitizer/sanitizer_reflect_test.gopin both the warning path and the nil-logger nil-safety invariant. If a future enhancement starts handling struct-valued maps, those tests must be updated (or replaced) to reflect the new behavior — do not delete them blind.
14.5 The Sanitizer Builds Its Own Decoder#
sanitizeXMLContent constructs an xml.Decoder directly rather than going through parser.NewSecureXMLDecoder, because it needs Strict = false and token-level access the parsers do not. That means every hardening the parsers get has to be repeated here by hand, and one was missing: with no CharsetReader, encoding/xml refuses any declaration other than UTF-8 with encoding %q declared but Decoder.CharsetReader is nil.
Real OPNsense writes <?xml version='1.0' encoding='us-ascii'?>, so opndossier sanitize failed outright on its most common input, and on testdata/sample.config.2.xml and sample.config.4.xml. The failure was easy to miss because the verification loop in CONTRIBUTING pipes stderr to /dev/null, so a crashed run and a clean run both show zero unredacted lines.
- When you add hardening to
pkg/parser/xmlutil.go, check whethersanitizeXMLContentneeds it too. The two decoders are independent. - The output is always UTF-8.
CharsetReaderdecodes the input, sowriteXMLDeclarationrewrites a non-UTF-8 declaration toencoding="UTF-8"; copying the original would label the file with an encoding it is not in. A UTF-8 or bare declaration is copied byte for byte so existing output does not shift. - Check exit codes, not just output, when testing the CLI.
sanitize ... 2>/dev/null | grephides a total failure as an empty result.
15. Liberal Boolean and Integer Parsing#
15.0 BoolFlag vs FlexBool vs FlexInt vs strict int/bool#
Four boolean/int handling styles coexist in the schema layer — pick the right one.
| Type | Where defined | XML input semantics | Use when |
|---|---|---|---|
opnsense.BoolFlag | pkg/schema/opnsense/common.go | absent → false; <tag/> → true; <tag>body</tag> → shared.IsValueTrue(body) | Field is a boolean toggle in OPNsense/pfSense XML. Absence of the element is meaningful (= disabled). |
shared.FlexBool | pkg/schema/shared/flex_bool.go | body → shared.IsValueTrue(body); no presence semantics | Field is a boolean but the element is always emitted and presence carries no signal. |
shared.FlexInt | pkg/schema/shared/flex_int.go | numeric → that value; on/yes → 1; off/no → 0; unknown non-numeric → wrapped error | Field must stay int-typed (may carry a count or a liberal toggle). |
strict int / bool | built-in | only decimal digits (for int); true/false only (for bool) | Field is genuinely numeric (UID, GID, PID, MTU) and non-numeric input is a real error. |
A presence toggle whose body must be ignored is a fifth case: type it *string and test for non-nil, as IPv6Allow does (§3.2). The OPNsense legacy rule's Floating is typed the same way, and its Quick is a *string for a third reason: an absent element takes the quick-unless-floating default and a present one is tested with !empty() (§3.8). The pfSense rule's Floating, Quick and Disabled are typed the same way: pfSense decides whether a rule is floating, whether it is quick and whether it is skipped with a bare isset(). Only its direction check also requires yes, and a rule that fails that check compiles as in whatever <direction> holds (compiledDirection). The converter warns when it ignores something the config says: a <direction> other than in on a rule that is not floating (Medium, warnOnIgnoredDirection), and a body other than empty or yes in <floating>, <quick> or <disabled> (Low, warnOnIgnoredFlagBody), since the GUI writes neither and a hand edit likely meant the opposite. BoolFlag reads <tag>0</tag> as false, where a bare isset() reads it as set. On Quick that misread is a false negative: a floating pass with <quick>0</quick> read as non-quick, so the block below it looked like the winner and a bypass was reported as troubleshooting.
One element can have two readings. Disabled on the legacy OPNsense rule is a *string for the opposite reason. From 17.7 OPNsense comments a rule out on !empty() (Rule.php parseIsComment), so <disabled/> and <disabled>0</disabled> are live rules and <disabled>no</disabled> is not. BoolFlag reads the first as set and the last as unset, and the shadow analysis drops a rule it believes disabled from winning a pair, so the misread loses a real finding. The converter tests the element with modelFlagSet and warns at Medium on an element it leaves live (warnOnLiveDisabledElement), since the config says disabled. Through 17.1 OPNsense tested isset(), so on those releases an empty element disabled a rule and opnDossier reports the rule as live, which is the safe direction. OPNsense writes only <disabled>1</disabled> and pfSense only an empty element, so a difference takes a hand edit or a generator, and no shipped fixture has one. Disabled on NAT rules, port forwards, routes, gateways, users and the pfSense VPN entries stays a BoolFlag and has not been checked against either vendor this way.
Both OPNsense and pfSense emit the same liberal truthy vocabulary (1|on|yes|true|enable|enabled, case-insensitive). Always go through shared.IsValueTrue / shared.IsValueFalse — never hand-roll a truthy parser at the call site.
That vocabulary is not universal, so read the vendor's form before choosing BoolFlag. pfSense's Form_Checkbox stores whatever value its constructor is given: yes by default, but Selected for the three adv_dhcp6_*_enable checkboxes on the interface page, and IsValueTrue rejects it. OPNsense 15.x stored Selected too. OPNsense releases through 26.7.4 save a DHCPv6 interface by copying every advanced DHCPv6 field into the config whether or not it was set, so an unticked box arrives as a self-closing element, which BoolFlag reads as ticked. For every value either GUI writes, interfaces.inc reads these elements as ticked exactly when they are non-empty (OPNsense's !empty() checks also treat "0" as unticked, but neither GUI writes "0"), so the schema keeps them as string and the converters compare against "". Typed as BoolFlag, they dropped every ticked pfSense and OPNsense 15.x box and reported all three as ticked on OPNsense DHCPv6 interfaces that had none ticked. TestConverter_InterfaceDHCPAdvancedV6_CheckboxValues in both parser packages pins the vendor values, and TestConverter_SampleConfig5_UntickedCheckboxesNotReported pins a config OPNsense wrote.
BoolFlag.UnmarshalXML was upgraded to delegate non-empty bodies through shared.IsValueTrue (previously it treated any element presence — even <tag>0</tag> — as true, silently dropping the body). Any code or test that relied on the old "presence = true regardless of body" behavior needs to be updated. See issue #558 and the plan at docs/plans/2026-04-18-002-fix-issue-558-parser-on-value.md.
BoolFlag is for toggles, never for an element that carries a value. It reads a self-closing element as true and runs any body through IsValueTrue, so on a value field it answers the wrong question: most set values read false, and an empty element, the form an unset user field can take, reads true. The #558 migration swept System.RrdBackup and NetflowBackup in with the genuine toggles, but they hold an hour interval, so a backup every 24 hours read as none. User.Expires, AuthorizedKeys, IPSecPSK and OTPSeed hold a date, keys, a PSK and a seed. All six are strings now. The converter decides whether the two backup intervals count as set, as it already does for IPv6Allow; nothing maps the four user fields into the model yet. The pfSense schema had Expires and AuthorizedKeys as strings all along, which is §3.3's advice again: diff a field against its twin in the other schema. These six are the ones found so far, not the result of checking every BoolFlag field against the vendor models, so check the vendor's field type before trusting one.
15.1 Pointer-Receiver MarshalXML and Value Marshaling#
opnsense.BoolFlag implements MarshalXML on a pointer receiver (*BoolFlag). When a struct containing a BoolFlag field is marshaled by value (not pointer), encoding/xml cannot find the pointer-receiver method and falls back to default bool serialization — producing <enable>true</enable> instead of <enable/>.
- Symptom:
BoolFlagfields serialize astrue/falsetext instead of presence-based empty elements. - Fix: Add a private type alias (e.g.,
type interfaceAlias Interface) and a pointer-receiverMarshalXMLon the parent struct that delegates viae.EncodeElement((*alias)(ptr), start). Also pass&value(notvalue) when encoding the struct within map-based containers likeInterfaces.MarshalXML. - Precedent:
pkg/schema/pfsense/interfaces.go—interfaceAliasand(*Interface).MarshalXML. - Rule: Any pfSense struct forked from opnsense that changes a field to
BoolFlagneeds this pattern. - Scope: The same pointer-receiver caveat applies to
shared.FlexBoolandshared.FlexInt— theirMarshalXMLmethods are also pointer-receiver. Any struct embedding one of these types that is subsequently marshaled by value (not pointer) will silently fall back to Go's defaultbool/intserialization, producing<tag>true</tag>or<tag>42</tag>instead of the canonical form. Use the same alias + pointer-receiverMarshalXMLworkaround on the parent struct.
See also: docs/solutions/runtime-errors/liberal-boolean-xml-parsing-opnsense-pfsense.md — full rollout of BoolFlag/FlexBool/FlexInt across OPNsense + pfSense schema, including the issue #558 <tag>0</tag> fix.
16. pfSense IPsec Enabled Flag#
16.1 Phase 1 Is the Gate#
convertIPsec() in pkg/parser/pfsense/converter_services.go sets common.IPsecConfig.Enabled = true only when len(ipsec.Phase1) > 0. Phase 2 tunnels and the mobile client configuration hang off Phase 1 in pfSense — without a Phase 1 entry they are functionally inactive, so the converter treats them as orphans: Enabled stays false and a medium-severity ConversionWarning is emitted for each orphan kind (IPsec.Phase2, IPsec.Client).
Downstream consumers (e.g., builder_vpn.go) short-circuit to "No IPsec configuration present" when Enabled is false — this is the correct behavior for orphan-only data, but breaks silently if the Phase 1 gate is ever weakened.
- Symptom: Valid Phase 1 tunnels show as "No IPsec configuration present" in reports (gate broken,
Enabledstuck atfalse). - Detection:
TestConverter_IPsecEnabled_Gotchas16inpkg/parser/pfsense/converter_ipsec_test.gois the canonical regression. If that test fails, the gate has drifted. - Fix: Keep the Phase 1 guard in
convertIPsecintact. Phase 2 or mobile client without Phase 1 must stay orphan-warned, not implicitly promoted toEnabled.
17. HybridGenerator Interface Coupling#
17.1 reportGenerator Must Stay Subset of ReportComposer#
hybrid_generator.go defines reportGenerator — a narrow interface that HybridGenerator uses internally. NewHybridGenerator accepts builder.ReportBuilder, which embeds ReportComposer. The constructor stores the ReportBuilder value into a field typed as reportGenerator. If a method is added to reportGenerator without also adding it to ReportComposer, the ReportBuilder interface no longer satisfies reportGenerator, and the assignment in NewHybridGenerator fails at compile time. Note: there is no standalone var _ reportGenerator = ... assertion — the compile-time check occurs at the assignment site in the constructor.
- Symptom:
cannot use reportBuilder (variable of interface type builder.ReportBuilder) as reportGenerator value - Fix: Add the method to both
reportGenerator(inhybrid_generator.go) andReportComposer(inbuilder/builder.go). - Precedent:
SetIncludeTunablesestablished this pattern;SetFailuresOnlywas added following the same approach.
17.2 narrowOnlyBuilder Test Mock#
hybrid_generator_test.go defines narrowOnlyBuilder — a minimal mock satisfying reportGenerator but NOT ReportBuilder. Adding a method to reportGenerator requires updating this mock.
- Symptom:
*narrowOnlyBuilder does not implement reportGenerator (missing method X) - Fix: Add a no-op method to
narrowOnlyBuilderinhybrid_generator_test.go.
See also: docs/solutions/logic-errors/documentation-code-drift-interface-refactoring.md — the ReportBuilder → SectionBuilder/TableWriter/ReportComposer split that produced this coupling and its documentation-drift aftermath.
18. Kea DHCP4 Schema Version Pinning#
18.1 Element Names Tied to MVC Model Version#
The KeaDhcp4 schema types in pkg/schema/opnsense/kea.go parse child elements named subnet4 (under <subnets>) and reservation (under <reservations>), matching the OPNsense MVC model KeaDhcpv4.xml v1.0.4. If a future OPNsense release renames these elements, the Go XML decoder will silently produce empty slices — no error, no warning, just missing data.
- Symptom: Kea DHCP configured in OPNsense but opnDossier reports "no Kea subnets."
- Detection: Compare
KeaDhcp4.Versionattribute against known versions. If it differs from1.0.4, investigate element name changes. - Prevention: When adding support for newer Kea MVC model versions, verify element names match by testing against a real config.xml from that version.
18.2 Pools Are Newline-Separated Inline Strings#
Kea's <pools> element on each <subnet4> stores newline-separated (\n) IP range or CIDR strings via KeaPoolsField — NOT comma-separated UUIDs referencing a separate container. There is no <pools> container at the dhcp4 level.
- Gotcha: Only the first pool entry is represented in
DHCPScope.Range. A conversion warning is emitted when multiple pools exist. - Source: Confirmed via
KeaPoolsField.phpin OPNsense core.
18.3 Reservations Reference Subnets, Not Vice Versa#
KeaReservation.Subnet contains the UUID of the parent subnet. The converter groups reservations by this field to attach them as static leases. Orphaned reservations (referencing nonexistent subnet UUIDs) emit a conversion warning.
- Gotcha: This is the inverse of what the OPNsense MVC model XML might suggest at first glance. The
<reservations>container is a flat sibling of<subnets>, not nested inside each subnet.
19. Sanitizer Rule Ordering#
19.1 authserver_config Must Precede password in builtinRules()#
ShouldRedactField iterates the rule slice and returns on the first match, so when two rules match the same field name the earlier one wins and the later one never runs. authserver_config pseudonymizes through MapAuthServerValue; the password rule flat-redacts to [REDACTED-PASSWORD].
- Problem: If
passwordis moved aboveauthserver_configin thebuiltinRules()slice, any field both rules match silently switches from pseudonymized to flat-redacted. No error or warning is emitted. - Symptom: Sanitized output shows
[REDACTED-PASSWORD]where a pseudonymized value is expected —MapAuthServerValuerendersldap_bindpwasBindPw-001-NotReal!(internal/sanitizer/mapper.go). - Fix: Ensure
authserver_configremains the first rule inbuiltinRules(). This pair genuinely competes:authserver.ldap_bindpwmatchesauthserver_configon its exact path pattern andpasswordon thebindpwsubstring, so the order decides whether the value is pseudonymized or flat-redacted. Verified —system.authserver.ldap_bindpwresolves toauthserver_configand yieldsBindPw-001-NotReal!, while a bareldap_bindpwfalls through topasswordand yields[REDACTED-PASSWORD]. - The
email-before-hostnameordering is a different case. It is the same first-match property but nothing currently depends on it:emailmatches the field patternemail,hostnamematcheshostname/domain/althostnames/hostnames, the two sets are disjoint, and thehostnamerule'sValueDetectorreturns early onIsEmailso it declines an email-looking value regardless of order. Keep it as insurance against a future overlapping pattern, but do not cite it as a live guard.
password does not reach ldap_bindpw through the pass substring. An earlier version of this entry said it did. It does not: ldap_bindpw contains none of the password rule's patterns — password, passwd, pass, pwd, bcrypt-hash, bcrypt_hash, sha512-hash. If the password rule matches ldap_bindpw at all, it is because an explicit bindpw pattern was added to its FieldPatterns, never through the generic pass substring. Two consequences worth keeping straight:
- The
bindpwpattern is what makes the ordering above load-bearing. Before it existed, everyauthserver_configpattern was anauthserver.*/system.authserver.*path containing nopassword-rule substring, so the two rules never competed and the ordering guidance was real but vacuous. Addingbindpwto thepasswordrule is what gave the pair a field they both match. - A bare
<ldap_bindpw>outside anauthserver.*path matched no credential rule on field name alone untilbindpwwas added; it was emitted verbatim in every mode. That was the leak the pattern closes.
The general lesson: a documented fallback is not a verified one. Check the actual FieldPatterns slice before relying on a rule to catch a field — a plausible-sounding substring claim is exactly the kind of thing that hides a leak.
19.2 A Rule That Declines Inside Its Redactor Consumes the Match#
First-match precedence has a second edge. A rule can match on field name and then decide, inside its Redactor, that it does not want the value after all — ip_address_field and subnet_field both did this, returning the value unchanged when it was not an IP or not a CIDR. That reads like declining, but the match was already consumed: ShouldRedactField had returned, so no later rule and no value-detector pass ever saw the value.
- Symptom: aggressive mode leaks values moderate redacts. Both offending rules are aggressive-only, so in moderate they are inactive and the value falls through to the detectors normally. An email in
<subnet>or<from>was pseudonymized in moderate and emitted verbatim in aggressive — the higher-privacy mode being the leaky one. - Not caught by the fixtures. No shipped config puts an email address in a
<subnet>or<from>element, so a fixture sweep passes against the broken code.TestModes_AggressiveRedactsEverythingModerateDoes_Syntheticcarries the invariant on probes built to trigger it; the fixture sweep beside it is the regression net for real-world shapes and is expected to be quiet. - Fix: declare the qualification on the rule as
FieldGuard func(value string) boolrather than implementing it in theRedactor. A rejected guard skips the rule and scanning continues.ShouldRedactFieldValueapplies it wherever the value is in hand;ShouldRedactFieldremains name-only for callers that genuinely have no value. - Why not fall through whenever a
Redactorreturns its input unchanged? That would mean invoking redactors speculatively, and redactors allocate pseudonyms in theMapperthat surface in the mapping report. Today's redactors happen to return before touching the mapper, but that is the same unenforced discipline whose absence caused this. AFieldGuardcannot allocate. - One declining redactor is left on purpose. The
usernamerule still returns its input for system accounts viaisSystemUser, so it consumes the match the same way. It is not a leak today: the values it declines (root,nobody,www) are ones moderate does not redact either, so monotonicity holds — verified by probe, not assumed. It becomes one the moment a valueisSystemUseraccepts is also something a moderate-mode rule would redact. Prefer aFieldGuardif you touch it. - Adding a rule with generic patterns? Patterns like
from,to, orsubnetmatch fields that have nothing to do with the rule. Give it aFieldGuard; do not test the value inside theRedactor.
19.3 A Generic Field Pattern Sometimes Needs FieldExclusions, Not a FieldGuard#
§19.2 says to give a rule with generic patterns a FieldGuard. That advice has a limit: a FieldGuard only ever receives the value. When the value cannot distinguish the fields, only the field name can, and a guard is the wrong tool.
The hostname rule lists domain as a FieldPattern, matched as a substring, so it claimed three DHCP dynamic-DNS TSIG metadata fields — ddnsdomainkeyname, ddnsdomainkeyalgorithm, and ddnsdomainalgorithm. A field-name match redacts unconditionally (§14.2), so in aggressive mode the literal hmac-md5 the audit engine reads became host-001.example.com. The rule is aggressiveOnly, so moderate and minimal were correct and aggressive — the mode operators pick when sharing most widely — was the broken one.
- The obvious fix is wrong, and quietly so.
FieldGuard: IsHostnamelooks right and would have leaked every firewall hostname in the repo.IsHostnamerequires at least one dot (TestIsHostnamepins{"localhost", false}), and every<hostname>value intestdata/is a single label:firewall,OPNsense,pfSense,printer,fw-test. The guard would decline on all of them, no later rule or detector would claim them, and aggressive mode would emit real hostnames verbatim. - No value predicate can work here.
hmac-md5andfw1are both valid single DNS labels. The discriminating information is the field name, not the value shape. - Fix:
FieldExclusions []stringonRule, honored inruleMatchesFieldName— the shared chokepointShouldRedactFieldandShouldRedactFieldValueboth call, so the two lookups cannot drift. It skips the rule without consuming the match, exactly likeFieldGuard. Matching is case-insensitive and anchored on the terminal path segment, sodhcpd.lan.ddnsdomainkeyalgorithmis excluded butddnsdomainis not. - The exclusion does not release hostnames. It suppresses only the unconditional name-based claim;
ShouldRedactValuestill runs its value-detector pass, and thehostnamerule'sValueDetectoris in it. A hostname-shaped value stored in an excluded field is still redacted.TestAggressiveMode_ExcludedTSIGFieldStillRedactsHostnamepins this. ddnsdomainalgorithmis the one you will miss. It does not containddnsdomainkey, so the exact-match pattern that protects the other siblings fromprivate_keydoes not cover it — and it is the most common of the three, appearing 71 times across the fixtures versus 4 forddnsdomainkeyalgorithm. Grep the fixtures rather than trusting a bug report's field list.- A fixture diff will look far bigger than the change.
Mappernumbers pseudonyms in encounter order, so releasing 71 values renumbers every laterhost-NNN. Mask the indices (s/host-[0-9]+/host-N/) before diffing, or you will be reading hundreds of lines of renumbering looking for the four that matter. - Regression tests:
TestRuleMatchesFieldName_FieldExclusions(mechanism),TestShouldRedactField_DDNSDomainKeySiblings(all three fields, all three modes),TestAggressiveMode_HostnameCoverageUnchanged(the redaction this must not narrow). - Do not "simplify" the exclusions into a
FieldGuard. The single-label hostname case above is why they are keyed on the field name.
20. pfSense Validator Injection#
20.1 SetValidator Is Guarded by sync.Once#
pkg/parser/pfsense.SetValidator installs the semantic validator used by Parser.ParseAndValidate. The slot is unexported (validateFuncHolder atomic.Pointer[...]) and is written exactly once per process — the first SetValidator call wins, every subsequent call is silently dropped. The atomic.Pointer pairs with sync.Once so the writer side synchronizes cleanly with the concurrent reader side in ParseAndValidate.
The one-shot lock is the enforcement point against a dynamically loaded compliance plugin's init() reassigning the validator after CLI setup. Because plugin.Open fires the loaded .so's init() at load time — later than Go's own init() ordering for in-tree packages — cmd/root.go:init calls SetValidator first, commits the sync.Once, and any subsequent plugin init() is effectively locked out. See the comprehensive-review ticket SEC-H2 / todos #105 and #128 for the original finding.
- Gotcha: Do NOT reintroduce a public mutable
ValidateFuncvariable. Any value that is directly assignable from plugin code re-opens the stomp hazard. The injection point MUST go throughSetValidator. - Gotcha: Test code that needs to swap validators across subtests uses the
ResetValidatorForTesting/ValidatorForTestinghelpers defined inpkg/parser/pfsense/export_test.go. These live in_test.goand therefore are NOT part of the public API — never promote them to a plain.gofile. - Gotcha: The exported
SetValidatoris safe to call from any goroutine; concurrent writers race to win thesync.Once, but only one does. Readers never see a torn value because the holder isatomic.Pointer[...]— verified byTestPfSense_SetValidator_Raceunder-race. - Regression tests:
TestPfSense_SetValidator_CannotBeOverwrittenpins the stomp-protection invariant;TestPfSense_SetValidator_Racepins the concurrent-writer safety. Both live inpkg/parser/pfsense/parser_test.go. If either fails, the §20 defense has regressed.
22. Documentation Tooling#
22.1 mdformat Collapses Consecutive **Label**: Lines#
With wrap = "no" in .mdformat.toml, mdformat joins consecutive **Label**: lines onto a SINGLE line. ADR frontmatter written as three lines —
**Date**: YYYY-MM-DD
**Status**: accepted
**Deciders**: ...
— renders after the pre-commit hook as one line: **Date**: YYYY-MM-DD **Status**: accepted **Deciders**: .... That collapsed form is canonical.
- Gotcha: Do not "fix" these back onto separate lines — the
mdformatpre-commit hook re-collapses them and the edit will not survive a commit. Bothdocs/adr/template.mdand the ADRs are kept in the collapsed form, so they are already mutually consistent. - Gotcha: Reviewers (e.g. CodeRabbit) sometimes flag the collapsed frontmatter as a layout defect and suggest splitting the lines. That suggestion is a false positive against this repo's formatter — decline it.
22.3 Cobra Use: Drives Generated Filenames — and macOS Hides the Fallout#
The root command's Use: string (cmd/root.go) is not just help text. Cobra derives from it:
- the page filenames under
docs/cli/(opndossier_audit.md, …) and the cross-reference links inside them, - the man-page filenames emitted by
opndossier man(opndossier.1), - every rendered
Usage:line.
Changing Use: therefore renames 19 committed doc files and one packaging artifact.
- The macOS trap: on a case-insensitive filesystem, regenerating writes
opndossier_audit.mdoveropnDossier_audit.mdand the directory entry keeps the old casing.git statusshows a modification, the build passes, and everything looks fine. On Linux CI the same regeneration produces a second, duplicate set of pages whilemkdocs.ymlstill points at the stale set. - Release coupling:
.goreleaser.yamlreferences./packaging/opndossier.1by exact path in two places (archivecontents:and nfpmcontents:).just ci-checknever runs goreleaser, so aUse:change that breaks these paths is invisible until agit tagfails the release workflow. - After any
Use:change: rungo run . docs docs/cli/, confirmgit ls-files docs/cli | grep -c '<old-casing>'returns0, run<binary> man <dir>and check the emitted.1name against both.goreleaser.yamlpaths, then updatemkdocs.yml,docs/for-agents.md, anddocs/llms.txt. - Regression test:
TestGetRootCmd(cmd/root_test.go) pinsUseto the lowercase shipped binary name and carries a comment explaining why. The name must match goreleaser'sbinary:(opndossier), Homebrew, andjustfile'sbinary_name.opnDossieris the product name in prose, never the command. - The macOS universal binary needs its own
name_template.universal_binariesdoes not inheritbinary:; withoutname_template: opndossierGoReleaser names the lipo output after the project,opnDossier, so the Darwin archive disagreed with every other platform and with the cask'sbinary "opndossier"stanza through v1.9.0. Default macOS volumes are case-insensitive, which is why nothing noticed. go installis the permanent exception. Go derives the installed binary name from the module path (github.com/EvilBit-Labs/opnDossier), sogo installproducesopnDossierregardless ofUse:. This cannot be fixed without changing the import path; it is documented as a rename step indocs/user-guide/getting-started.mdandinstallation.mdinstead.
22.4 foo.md and foo/index.md Silently Collide#
MkDocs maps both docs/foo.md and docs/foo/index.md to the same output path, site/foo/index.html. One silently wins; the other is never served. --strict does not catch this — there is no broken link, just a page that renders someone else's content.
- Live example:
docs/examples.mdanddocs/examples/index.mdboth built tosite/examples/index.html.examples/index.mdwon, so the "All Examples" nav entry pointed at a URL rendering the Overview page. The condition survived undetected because every link still resolved. - Detection:
for f in docs/*.md; do [ -d "docs/$(basename "$f" .md)" ] && echo "COLLISION: $f"; done - Rule: when splitting a page into a directory, delete the original. Do not leave both.
- Corollary for
mkdocs-redirects: never add aredirect_mapentry whose source collides with a real page's output path.examples.md: examples/index.mdwrites a redirect stub oversite/examples/index.html— the very page it points at — replacing the Overview content with a self-redirect.--strictreports nothing. A colliding source needs no redirect anyway: the URL never changed meaning, only which file backed it.
22.5 just generate-docs Does Not Write the Served Model Reference#
docs/data-model/model-reference.md, the page mkdocs serves as "Model Reference", is hand-maintained. The generate-docs recipe runs tools/docgen/main.go, which reflects over the vendor XML schema types in pkg/schema and writes docs/templates/model-reference.md, a different file mkdocs does not serve and that has no InboundNATRule section. Until #899 the served page carried an "auto-generated, regenerate with just generate-docs" banner, and one session trusted it: it regenerated the templates page, grepped it for the type it had changed, found nothing, and concluded no documentation update was needed.
- When you change a
pkg/modeltype: regenerate the API snapshot (TestPublicAPISnapshot -update, undermise exec) and hand-edit the type's table indocs/data-model/model-reference.mdin the same commit. Do not runjust generate-docsfor this. - A banner naming a generator is a claim to verify, not provenance: check the generator's output path and the site's nav entry. Full write-up:
docs/solutions/workflow-issues/model-reference-banner-points-at-wrong-generator-output.md.
22.2 mdformat Excludes Live in .pre-commit-config.yaml, Not .mdformat.toml#
File exclusions for the mdformat hook are the pre-commit hook's native exclude: regex in .pre-commit-config.yaml (currently *.golden.md, docs/cli/, CHANGELOG.md, *.tpl.md). Do NOT reintroduce an exclude = [...] list in .mdformat.toml: that feature requires the hook to run under Python 3.13+, but pre-commit builds the hook venv with its own interpreter (3.11 today), so it fails on every markdown file with 'exclude' patterns are only available on Python 3.13+.
23. Unused-Object Detection#
23.1 Reachability Edge-Building Must NOT Mirror resolveNode#
DetectUnusedObjects (internal/analysis/unused.go) frames unused-alias detection as graph reachability from policy roots. The obvious implementation — reuse NamedObjects.resolveNode's member walk — is a bug. resolveNode (pkg/model/named_objects.go) early-returns for any isDynamic() type, and staticNamedObjectTypes is only {host, network, port}. Converters store the raw vendor type string verbatim (common.NamedObjectType(a.Type)), so a vendor networkgroup group alias is classified dynamic even though its members are alias names.
- Symptom: an alias referenced only via a rule →
networkgroupgroup → alias chain is falsely reported unused, breaking the nested-group case the feature centers on. - Rule: reachability uses its own predicate — for every object, for every member, add an edge if the member keys into
NamedObjects, with noisDynamicgate. It only asks "does this member name another object?", never "do the members expand into literal addresses?" It stays correct for opaque types (url/geoip/external) because their members (URLs, country codes) do not key into the registry and so contribute no edges without needing a type check. - Regression test:
TestDetectUnusedObjectscase "does not flag alias nested under a used networkgroup-typed group" (internal/analysis/unused_test.go). If it fails, someone reintroduced theisDynamicgate.
23.2 Disabled Rules Are Roots; Remediation Hedges#
Root collection in collectRoots deliberately does not skip disabled rules. A disabled rule referencing an alias means the alias is staged, not dead — deleting it breaks the rule on re-enable. This is easy to "optimize" away by adding a !rule.Disabled guard; don't.
Relatedly, the finding's Recommendation intentionally hedges ("confirm before removing") rather than instructing deletion. The detector cannot see a config-invisible staging signal — an alias created before its referencing rule exists leaves no trace, and creation timestamps are not in config.xml. A flat "safe to delete" would be an outage recommendation for that case. Both invariants are pinned by TestDetectUnusedObjects ("does not flag alias referenced only by disabled rule") and TestDetectUnusedObjects_FindingShape.
The shadow analysis splits the two sides. A disabled rule cannot win a pair, because the firewall does not load it (derivePairWinnerLoser), and it does not stop a deny above it from being the terminal rule (isTerminalDefaultDeny). Each vendor has its own test for that: pfSense skips a rule on isset(), whatever <disabled> holds (filter.inc L3256, L4267), and OPNsense comments one out on !empty() (Rule.php parseIsComment), so <disabled/> is a live rule there. Each converter applies its vendor's test (§15.0), because Disabled decides findings here. A disabled rule can still lose a pair, since it is staged and would lose if it were enabled. DetectDeadRules is the exception: normalizeForDeadRuleView clears Disabled, so a disabled block-all still owns an unreachable finding as it always did. A new filter in the shadow core has to be cleared there too.
Disabled is the only skip the analysis sees. pfSense also leaves out a rule on an interface that is not enabled (filter.inc L3287, L3297), and unticking Enable on an interface keeps its entry and its rules, so a config can hold a pair the firewall loads neither side of. That pair still resolves, and a pass above a block reads as a bypassed deny. The finding over-reports: it describes what the firewall would do if the interface came back, not what it does now.
The byte-for-byte contract on DetectDeadRules covers what it does with the rules it is given, not what a converter gives it. RulesEquivalent compares the converted rules, Quick, Direction and Disabled among their fields, so reading a rule as its firewall does changes what counts as a duplicate, on both vendors. On pfSense that takes <quick> or <direction> on an interface rule, a <quick> holding 0 or a word such as no on a floating rule, a <floating> that does not hold yes, <floating>yes</floating> with no <direction>, or a <disabled> holding 0 or a word such as no. On OPNsense it takes <disabled/>, or a <disabled> holding a word such as no, a <quick> holding 0 or nothing on an interface rule, a <quick> holding a word such as no on a floating rule, or an empty <floating/>. Of these only <quick>0</quick> is written by a GUI, the legacy OPNsense rules page. TestConverter_DeadRules_SeeRulesAsCompiled and TestConverter_FilterRules_DeadRulesSeeDisabledReading pin the pfSense and <disabled> shapes; TestConverter_FilterRules_LegacyQuickElement and TestConverter_FilterRules_LegacyFloatingElement pin the OPNsense <quick> and <floating> readings on the converted rule.
23.3 R6 Completeness Is a Manual Surface Audit, Not Automatic#
The "no false positive" guarantee holds exactly as far as the typed-ObjectRef root sites in collectRoots cover every CommonDevice field on which a pf-family alias can appear. When a new device parser or a new CommonDevice address/port field lands, it must be audited: an alias-capable field needs both an *ObjectRef model field, or []ObjectRef for an address list (populated by the converter), and a collectRoots entry. Traffic-shaper and captive-portal config are modeled as opaque identifier strings (not addresses) and are correctly excluded; DNS/NTP/monitor/LB fields are literal IPs, not firewall aliases. A silently-untracked alias-capable field reintroduces the false-positive class.
An outbound NAT alias is the instance most easily missed, because the field exists and is populated for one shape only. Both GUIs write the alias to <network>, where AliasAddress returns nothing, so both convertOutboundNATRules look it up on EffectiveAddress. Until they did, a rule in the GUI's shape held no reference, and audit listed an alias in use as unused. TestConverter_OutboundNAT_AliasInNetwork in both parser packages decodes that shape.
The diff's alias rating keeps a second list of the rule references: activeAliases in internal/diff/analyzer_aliases.go decides which alias changes are rated medium, and it reads only enabled rules, and outbound NAT rules only in the two modes that load them. A reference field on a firewall rule, outbound NAT rule or port forward needs a line there too; TestActiveAliases_EveryRuleReferenceCounts sets each one in turn and fails until it has one; without it, a change to an alias used only through that field is rated low.
24. GitHub Action#
24.1 The Action Must Run As the Workspace Owner#
The published image sets USER 65532:65532, which is the correct default for a bare docker run. A runner workspace is owned by the runner user (uid 1001 on GitHub-hosted runners), so without --user "$(id -u):$(id -g)" on the docker run line the container cannot write into the bind mount. Every invocation using the documented output input failed with permission denied; stdout-only runs were unaffected.
-
Test the Action with an output file, not just stdout. The breakage is invisible to any check that only asserts the command exits 0 while printing to stdout, which is why it shipped.
-
Reproduce it locally by chowning a scratch workspace to a uid the image does not run as:
docker run --rm -v "$WS:/data" -w /data <image> convert config.xml --format json --output report.jsonWithout
--userthat fails; with--user 1001:1001it writesreport.jsonowned by 1001 at mode 600 (export.DefaultFilePermissions). -
Do not "fix" this by dropping
USERfrom the Dockerfile. The non-root default protects directdocker runusers; the Action overrides it only because it has a bind mount to match.
25. Lint Gate Self-Satisfaction#
25.1 fix: true Makes golangci-lint run Unable to Fail#
.golangci.yml set fix: true under issues:, which applies to every fixable finding, and that includes every formatter in the formatters: block. run repaired each one in place and then reported 0 issues with exit 0. CI's Lint job invokes a bare golangci-lint run, so the repair landed in the runner's own checkout and was thrown away with it. Formatting drift could not turn the job red, and just lint behaved the same way on a developer machine.
Reproduce on any revision carrying the key by adding stray indentation to a .go file:
$ golangci-lint run
0 issues. # exit 0
$ git diff --stat # empty: the indentation was repaired, never reported
- Rule: rewriting is opt-in at the call site, never in config.
just formatand the pre-commit hook pass--fixexplicitly, andgolangci-lint fmtrewrites by design. Nothing else may mutate the tree. - CI's step also passes
args: --fix=false, which overrides afix:key if one is ever restored. Verified against a config withfix: truepresent. - Same trap, second location, and mind the caveat.
just format-checkrangolangci-lint fmt ./..., which rewrites rather than checks, so that recipe could never fail on its own.just ci-checkdid still catch drift, but at the earliercheckstep, where pre-commit fails any hook that modified files, and the tree was silently reformatted on the way past.format-checknow passes--diffso it gates where its own description says it does. Treatlintas the authoritative formatter gate regardless, sincefmtandruncan disagree about the same file (section 25.2). - Verify a change to this gate locally, not with a probe commit.
act -j lint -P ubuntu-latest=catthehacker/ubuntu:act-latestruns the real Lint job. Check both directions, green on a clean tree and red with a misformat planted, because a one-sided pass proves nothing. Without-P, and with no~/.config/act/actrcon the machine, act prompts for an image size and exitslevel=fatal msg=EOF, which looks like a failing gate and is not one.
25.2 A Construct Can Have No Formatting That Passes#
golines and gofumpt both run in the formatters: pipeline and disagreed permanently on a multi-value return of two composite literals. golangci-lint fmt produced a shallow form that run rejected as gofumpt; gofmt -w produced a deeper form that run rejected as gci. No file content satisfied both, and fix: true hid the standoff by rewriting on every run and reporting nothing.
- Symptom: a formatter finding that successive PRs each report as pre-existing and each defer. Three did before this was traced.
- Change the code, not the pipeline. The deadlock is specific to brace-wrapped literals inside a multi-value
return. Putting each literal on a single line and wrapping the second return value onto its own line converges:gofmt,golinesandgofumptall accept that shape, and it stays accepted when a literal later grows past thegolineslimit and gets rewrapped. Reordering or dropping a formatter was the more disruptive option and proved unnecessary. - The config change and the code change are load-bearing together. Closing the gate on a tree that still contains the standoff turns
mainred immediately.