Skip to content

fix: Drop context attributes that are not JSON types from analytics events - #311

Merged
keelerm84 merged 1 commit into
mainfrom
mk/SDK-3784/redact-other-objects
Dec 3, 2026
Merged

keelerm84 merged 1 commit into
mainfrom
mk/SDK-3784/redact-other-objects

Conversation

@keelerm84

@keelerm84 keelerm84 commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

The event serializer can only redact private attributes inside JSON values: null, bool, int, float, string, array, and stdClass. A context attribute whose value is, or contains, any other object (a JsonSerializable, a class with public properties, DateTime, ArrayObject, and so on) was sent to json_encode as is, so private attribute references inside it were not applied.

The serializer now checks each custom attribute. If the value is or contains a type other than a JSON type, the attribute is left out of the event and a warning is logged through the configured logger. Attributes that are private as a whole are still redacted as before and do not log a warning.

Behavior change: contexts that use objects other than stdClass as attribute values, including DateTime, no longer send those attributes in analytics events. Flag evaluation is unchanged. The LDContextBuilder::set() docs now say to use only JSON types.

This matches the approach agreed with the JS SDK maintainer. Follows #306 and #309.

Ticket: SDK-3784


Note

Overview
Analytics events now validate context custom attributes with a new isJsonValue check before serialization. Values that are not JSON types (null, scalars, arrays, stdClass) or that nest disallowed objects (DateTime, JsonSerializable, arbitrary classes, etc.) are omitted from the event payload, and the SDK emits a warning via the configured PSR-3 logger (defaults to silent NullLogger).

Nested invalid types cause the whole attribute to be dropped; valid siblings and purely JSON structures are unchanged. Attributes marked fully private still redact without a warning, so private paths inside non-JSON values are no longer a redaction gap. Flag evaluation is unaffected—only event export behavior changes.

LDContextBuilder::set() documentation now states that only JSON types should be used in attribute values if they are to appear in analytics.

Reviewed by Cursor Bugbot for commit 7538d66. Bugbot is set up for automated code reviews on this repo. Configure here.

…vents

A context attribute value that is, or contains, an object other than
stdClass can not be redacted reliably. The event serializer now leaves
the attribute out of analytics events and logs a warning.
@keelerm84
keelerm84 requested a review from a team as a code owner December 2, 2026 14:38

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium. Not approved: SDK rules 1–3 would allow this (not a release PR, allowed author, no workflow-file changes), but the configured approval threshold is low only and this changes analytics-event privacy redaction. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver

@keelerm84
keelerm84 merged commit 3e9104b into main Dec 3, 2026
17 checks passed
@keelerm84
keelerm84 deleted the mk/SDK-3784/redact-other-objects branch December 3, 2026 17:50
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.

2 participants