Skip to content

Conversation

@rgarcia
Copy link
Contributor

@rgarcia rgarcia commented Jan 29, 2026

Summary

  • Fix bug where DefaultGeolocationSetting (and any other non-struct fields) were silently dropped when AddExtension performed a read-modify-write cycle on policy.json
  • Simplify Policy struct to only include fields we programmatically modify (ExtensionInstallForcelist, ExtensionSettings)
  • Add custom UnmarshalJSON/MarshalJSON methods to preserve all unknown JSON fields

Context

This fixes an issue introduced by #136, which added DefaultGeolocationSetting to policy.json. The Go Policy struct didn't have this field, so when the JSON was unmarshaled and re-marshaled (e.g., during AddExtension), the field was silently dropped.

Solution

Instead of requiring every Chrome policy field to be defined in the Go struct, we now:

  1. Only define struct fields for settings we need to modify programmatically
  2. Preserve all other fields through an unknownFields map[string]json.RawMessage

This means you can add any Chrome policy setting to policy.json without Go code changes.

Test plan

  • Added unit tests for field preservation through unmarshal/marshal cycles
  • Tests verify unknown fields survive modification of known fields
  • go build ./... passes
  • go test ./lib/policy/... passes

Note

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.json read-modify-write behavior so non-modeled Chrome policy fields are preserved instead of being silently removed when updating extension policies.

This simplifies Policy to only the fields the code mutates (ExtensionInstallForcelist, ExtensionSettings) and adds custom MarshalJSON/UnmarshalJSON logic to round-trip all other keys via an unknownFields map. New unit tests cover unknown-field preservation, modifying known fields while retaining unknown ones, and ExtensionInstallForcelist round-tripping.

Written by Cursor Bugbot for commit 81e35e8. This will update automatically on new commits. Configure here.

…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.
@rgarcia rgarcia requested a review from archandatta January 29, 2026 13:43
@rgarcia rgarcia merged commit 640ca69 into main Jan 29, 2026
5 checks passed
@rgarcia rgarcia deleted the fix/preserve-unknown-policy-fields branch January 29, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants