Repository navigation
fix: Redact nested private attributes when attribute values are stdClass objects - #306
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.
|
@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.
|
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 |
zigzagdev
left a comment
There was a problem hiding this comment.
Thank for reviewing and following commit.
Your changes look good to me!
🤖 I have created a release *beep* *boop* --- ## [6.13.2](6.13.1...6.13.2) (2026-11-30) ### Bug Fixes * Escape attribute names that look like references in redactedAttributes ([#309](#309)) ([d59cb4b](d59cb4b)) * Evaluate before and after clauses on timestamps with up to nine fractional digits ([#308](#308)) ([a174822](a174822)) * Redact nested private attributes in associative arrays that have ([1c5dba7](1c5dba7)) * Redact nested private attributes when attribute values are `stdClass` objects ([#306](#306)) ([1c5dba7](1c5dba7)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
Thank you again @zigzagdev! This has been released in 6.13.2 |
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.