Repository navigation
Conversation
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.
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
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.
Requirements
Related issues
None.
Describe the solution you've provided
Private attribute redaction only handled associative arrays, so nested private attributes inside
stdClassvalues were sent unredacted.So, this PR affects contexts created with
LDContext::fromJson(), which decodes JSON objects asstdClass.This change applies the same redaction to
stdClassvalues and keeps them as JSON objects after redaction, including when their property names are numeric.Describe alternatives you've considered
Converting
stdClassvalues to associative arrays inLDContext::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 fromLDContext::fromJson()is redacted.testObjectPropertyRedactionWithStdClassValues: nested and numeric-named properties ofstdClassvalues are redacted, and the result stays a JSON object.testRedactingEveryPropertyOfStdClassValueLeavesEmptyObject: redacting every property leaves{}.The new tests fail without the fix (run against
main'sEventSerializer.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
Note
Overview
Event serialization now applies nested private attribute redaction when custom values are
stdClass(for example nested fields fromLDContext::fromJson()), not only associative arrays.EventSerializer::redactJsonValuewalks object properties withget_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
EventSerializerTestcases cover JSON-parsed contexts, nestedstdClassvalues, and"b":{}output.Reviewed by Cursor Bugbot for commit eb9cc06. Bugbot is set up for automated code reviews on this repo. Configure here.