fix: preserve unknown fields in policy.json during read-modify-write cycles #138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
DefaultGeolocationSetting(and any other non-struct fields) were silently dropped whenAddExtensionperformed a read-modify-write cycle onpolicy.jsonPolicystruct to only include fields we programmatically modify (ExtensionInstallForcelist,ExtensionSettings)UnmarshalJSON/MarshalJSONmethods to preserve all unknown JSON fieldsContext
This fixes an issue introduced by #136, which added
DefaultGeolocationSettingtopolicy.json. The GoPolicystruct didn't have this field, so when the JSON was unmarshaled and re-marshaled (e.g., duringAddExtension), the field was silently dropped.Solution
Instead of requiring every Chrome policy field to be defined in the Go struct, we now:
unknownFields map[string]json.RawMessageThis means you can add any Chrome policy setting to
policy.jsonwithout Go code changes.Test plan
go build ./...passesgo test ./lib/policy/...passesNote
Medium Risk
Touches JSON (un)marshaling for enterprise policy persistence; bugs here could corrupt or drop policy settings during writes, though changes are localized and covered by new tests.
Overview
Fixes
policy.jsonread-modify-write behavior so non-modeled Chrome policy fields are preserved instead of being silently removed when updating extension policies.This simplifies
Policyto only the fields the code mutates (ExtensionInstallForcelist,ExtensionSettings) and adds customMarshalJSON/UnmarshalJSONlogic to round-trip all other keys via anunknownFieldsmap. New unit tests cover unknown-field preservation, modifying known fields while retaining unknown ones, andExtensionInstallForcelistround-tripping.Written by Cursor Bugbot for commit 81e35e8. This will update automatically on new commits. Configure here.