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. |
Build on the stdClass redaction fix: - Treat an associative array with any numeric key as a JSON object, the same way json_encode does (array_is_list). Before, the first numeric key returned the array unredacted. If a key was already redacted, the event also listed it in _meta.redactedAttributes. - Return redacted objects as objects, so an array that is a list after redaction still serializes as a JSON object. - Stop redaction at the json_encode depth limit, so a value with a cycle makes json_encode fail instead of exhausting memory.
Member
|
Thanks for this fix, @zigzagdev. I used the maintainer-edit access to push one more commit to this branch (0bfc9d9). It builds on your change and leaves your commit and tests as they were. The commit changes three things in
New tests cover each case, plus multi-kind contexts, escaped path components, lists, and parity between A separate fix for how attribute names that start with |
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.
fix: Redact nested private attributes in associative arrays that have numeric keys
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 redacts nested private attributes inside
stdClassvalues (typical for contexts fromLDContext::fromJson()), not only associative arrays.redactJsonValuetreatsstdClassand non-list arrays like JSON objects, coerces keys to strings for path matching, and returns(object)$retso redacted structures still encode as{}objects—including numeric property names and fully redacted objects.serializeEventspasses an explicitMAX_JSON_DEPTH(512) tojson_encode, and redaction stops at the same depth to avoid infinite recursion on cycles and to align with encode failure behavior (empty payload when encode fails).Adds broad
EventSerializerTestcoverage for JSON-parsed contexts, multi-kind contexts, lists vs objects, escaped path components, non-mutating redaction, cyclic/deep values, and numeric keys.Reviewed by Cursor Bugbot for commit 0bfc9d9. Bugbot is set up for automated code reviews on this repo. Configure here.