Skip to content

Analytics: updateEventIfRequired mutates the shared ext.prebid.analytics node #4716

Open

Description

@patmmccann

🤖 This issue was written by an AI agent (Claude Code) on behalf of @patmmccann.

What happens

updateEventIfRequired → updateAuctionContext merges the account's analytics.modules.<reporter> config into ext.prebid.analytics.<reporter> for each reporter, but it writes into the request's existing JsonNode objects instead of copies:

final JsonNode analyticsNode = extRequestPrebid != null ? extRequestPrebid.getAnalytics() : null;
if (analyticsNode != null && analyticsNode.isObject()) {
final ObjectNode adapterNode = Optional.ofNullable((ObjectNode) analyticsNode.get(adapterName))
.orElse(mapper.mapper().createObjectNode());
moduleConfig.fields().forEachRemaining(entry -> {
final String fieldName = entry.getKey();
if (!"enabled".equals(fieldName) && !adapterNode.has(fieldName)) {
adapterNode.set(fieldName, entry.getValue());
}
});
((ObjectNode) analyticsNode).set(adapterName, adapterNode);

  • adapterNode is the live analyticsNode.get(adapterName) when it exists, and adapterNode.set(...) adds the account fields to it.
  • ((ObjectNode) analyticsNode).set(adapterName, adapterNode) changes the shared ext.prebid.analytics object.

The new BidRequest/AuctionContext built afterwards still points to the same, now changed, node.

Which node is shared:

Reporters run one after another through vertx.runOnContext. So when a reporter that shares the node runs after another reporter's config was merged into it, it sees the earlier reporter's account-level module config under the earlier reporter's key.

Why it matters

Account-level analytics module config (e.g. per-publisher keys or scope IDs for a reporter) could end up visible to other reporters. Which reporters see it depends on reporter order. Changing the request in place from inside the analytics path is also fragile if anything else reads the request afterwards.

To reproduce

Two reporters enabled, e.g. pubstack and greenbids. Account config:

{ "analytics": { "modules": { "pubstack": { "key1": "a" }, "greenbids": { "key2": "b" } } } }

An AMP (via stored request) or video request with "ext": {"prebid": {"analytics": {"pubstack": {}, "greenbids": {}}}}: the reporter that runs second sees the other reporter's merged account fields in ext.prebid.analytics.

Expected behaviour

Each reporter gets its own copy of ext.prebid.analytics (ideally trimmed to its own entry), and the request object isn't changed.

Suggested fix

Work on analyticsNode.deepCopy() (and a copy of the adapter node) in updateAuctionContext, and build the new ExtRequestPrebid from that copy.

References

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions