Skip to content

fix: Redact nested private attributes when attribute values are stdClass objects - #306

Open
zigzagdev wants to merge 1 commit into
launchdarkly:mainfrom
zigzagdev:fix/redact-private-attributes-in-object-values
Open

zigzagdev wants to merge 1 commit into
launchdarkly:mainfrom
zigzagdev:fix/redact-private-attributes-in-object-values

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Nov 21, 2026 •

Copy link
Copy Markdown

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

None.

Describe the solution you've provided

Private attribute redaction only handled associative arrays, so nested private attributes inside stdClass values were sent unredacted.
So, this PR affects contexts created with LDContext::fromJson(), which decodes JSON objects as stdClass.

This change applies the same redaction to stdClass values and keeps them as JSON objects after redaction, including when their property names are numeric.

Describe alternatives you've considered

Converting stdClass values to associative arrays in LDContext::fromJson(). That would change the attribute values that callers get back from the context, so I kept the fix in the serializer, where redaction happens.

Added some tests in tests/Impl/Events/EventSerializerTest.php:

  • testObjectPropertyRedactionInContextParsedFromJsonString: a private attribute nested in a context from LDContext::fromJson() is redacted.
  • testObjectPropertyRedactionWithStdClassValues: nested and numeric-named properties of stdClass values are redacted, and the result stays a JSON object.
  • testRedactingEveryPropertyOfStdClassValueLeavesEmptyObject: redacting every property leaves {}.

The new tests fail without the fix (run against main's EventSerializer.php):

    Tests: 3, Assertions: 3, Failures: 3.
    Failed asserting that '[{...,"context":{"key":"user-key","kind":"user","b":{"prop1":true}}}]' contains ""b":{}".

With the fix:

    OK (3 tests, 5 assertions)

Additional context

Full suite on the CI PHP matrix following

PHP Dependencies Result
8.2 latest / lowest OK (Tests: 562, Assertions: 1504, Skipped: 21)
8.3 latest / lowest OK (Tests: 562, Assertions: 1504, Skipped: 21)
8.4 latest / lowest OK (Tests: 562, Assertions: 1504, Skipped: 21)

Note

Overview
Event serialization now applies nested private attribute redaction when custom values are stdClass (for example nested fields from LDContext::fromJson()), not only associative arrays.

EventSerializer::redactJsonValue walks object properties with get_object_vars, matches paths the same way as for arrays, and returns an object when the input was an object so JSON still uses {} (including numeric property names and empty objects after full redaction).

Three EventSerializerTest cases cover JSON-parsed contexts, nested stdClass values, and "b":{} output.

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

A context that LDContext::fromJson() decodes from a string stores JSON
objects as stdClass. The event serializer only applied nested private
attribute redaction to associative arrays, so properties such as
/address/street were sent in analytics events. Redaction now applies to
stdClass values too, and a redacted object stays a JSON object.
@zigzagdev
zigzagdev requested a review from a team as a code owner November 21, 2026 05:45
@keelerm84

Copy link
Copy Markdown
Member

@zigzagdev just wanted to acknowledge that we have seen this PR. I haven't had a chance to dig into it yet, but will try to get to it this week if I'm able.

This branch has not been deployed

No deployments
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