#121

JSONPath lookup resolves inherited properties as payload data

Opensdivyanshu90opened 20d ago

What is the issue?

The restricted JSONPath evaluator resolves inherited object and array properties instead of treating them as absent.

JSON values contain only their own data properties. Returning an inherited value violates the Json return contract and breaks the strict lookup rule that a missing path must remain missing.

How to reproduce

Evaluate these paths against an empty JSON object:

getPath({}, "$.constructor");
getPath({}, "$.toString");

Observed behavior

Both calls return inherited functions from Object.prototype. Through utils.json.get or optionalGet, a path absent from the vendor payload is therefore treated as present and can return a non-JSON value.

Numeric array traversal has the same ownership gap because it also indexes without checking whether the element is an own property.

Expected behavior

Both paths should return undefined. Traversal should continue only through own object properties and own array elements.

Root cause

getPath validates the container type and then directly indexes current[key]. JavaScript property access walks the prototype chain unless ownership is checked explicitly.

Proposed resolution

Require Object.hasOwn at every object-member and array-index traversal step, and add regression coverage for inherited object members and array indices.

Activity

0

No activity yet.