Skip to content

VocabularyManager.getTerm returns Object.prototype built-ins for property names that shadow Object.prototype (hasOwnProperty, constructor, toString, …) #1241

Closed

Description

@mon7792

VocabularyManager.getTerm returns a built-in Object.prototype method (a Function) instead of the YAML vocabulary string when a property name matches a key on Object.prototype — such as hasOwnProperty, constructor, or toString.

Root Cause

In vocabulary.js line 143:

const property = decl.properties.find(d => d[propertyName]);

Each element d in decl.properties is a plain {} object. For any propertyName that exists on Object.prototype, d[propertyName] walks the prototype chain and returns the built-in method — which is truthy. As a result:

  1. find always returns the first element in the array (all plain objects inherit these)
  2. property[propertyName] on line 144 then returns the built-in Object.prototype method
  3. The caller receives a Function, not the vocabulary string

Note: the fix proposed in #1184 (propertyName in d) does not fix this — 'hasOwnProperty' in {} also returns true via the prototype chain. The correct fix is Object.prototype.hasOwnProperty.call(d, propertyName).

Steps to Reproduce

const { VocabularyManager } = require('@accordproject/concerto-vocabulary');
const vm = new VocabularyManager();

const vocab = `
locale: en
namespace: org.test@1.0.0
declarations:
  - Book: A book
    properties:
      - hasOwnProperty: Custom term
      - constructor: Custom constructor term
      - toString: Custom toString term
`;

vm.addVocabulary(vocab);

console.log(vm.getTerm('org.test@1.0.0', 'en', 'Book', 'hasOwnProperty'));
// Expected: "Custom term"
// Actual:   [Function: hasOwnProperty]  ← Object.prototype.hasOwnProperty

console.log(vm.getTerm('org.test@1.0.0', 'en', 'Book', 'constructor'));
// Expected: "Custom constructor term"
// Actual:   [Function: Object]          ← Object.prototype.constructor

console.log(vm.getTerm('org.test@1.0.0', 'en', 'Book', 'toString'));
// Expected: "Custom toString term"
// Actual:   [Function: toString]        ← Object.prototype.toString

Affected Property Names (non-exhaustive)

Any name present on Object.prototype:
hasOwnProperty, constructor, toString, valueOf, isPrototypeOf, propertyIsEnumerable, toLocaleString

Possible Solution

Replace the plain property access on line 143 of vocabulary.js with an own-property check:

// Before — traverses the prototype chain; shadowed by Object.prototype built-ins
const property = decl.properties.find(d => d[propertyName]);

// After — checks only own properties; immune to prototype shadowing
//         and also fixes falsy-value coercion (see #1183) as a side-effect
const property = decl.properties.find(d => Object.prototype.hasOwnProperty.call(d, propertyName));

This single-line change also subsumes the falsy-value fix from #1183 because Object.prototype.hasOwnProperty.call tests key existence, not value truthiness — so "", false, and 0 are handled correctly too.

Relationship to #1183

#1183 covers falsy-value coercion ("", false, 0 → null). The proposed fix there (propertyName in d) would partially address falsy values but would not resolve this prototype pollution bug. Using Object.prototype.hasOwnProperty.call(d, propertyName) fixes both issues with a single change.

Environment

  • Package: @accordproject/concerto-vocabulary
  • Runtime: Node.js (any version)
  • Concerto version: current main

Activity

  1. github-actions commented on Jul 26, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open with no activity. Remove the stale label or comment to keep it active. Only items with maintainer engagement are auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions