fix: preserve unknown fields in policy.json during read-modify-write cycles#138
Merged
fix: preserve unknown fields in policy.json during read-modify-write cycles#138
Conversation
…cycles The Policy struct only defined fields it explicitly used, causing any other fields in policy.json to be silently dropped when AddExtension performed a read-modify-write cycle. This broke the DefaultGeolocationSetting added in #136. Changes: - Add custom UnmarshalJSON/MarshalJSON to preserve unknown JSON fields - Simplify Policy struct to only include fields we programmatically modify (ExtensionInstallForcelist, ExtensionSettings) - All other Chrome policy settings are now automatically preserved - Add comprehensive tests for the preservation behavior This allows policy.json to contain any Chrome policy setting without requiring Go struct updates, as long as we don't need to modify it in code. Fixes issue introduced by #136
Use a separate policyJSON struct without the mutex for JSON operations to satisfy go vet checks.
archandatta
approved these changes
Jan 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.