Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions lib/handlebars/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ export function isFunction(value) {
return typeof value === 'function';
}

function testTag(name) {
const tag = '[object ' + name + ']';
return function (value) {
return value && typeof value === 'object'
? toString.call(value) === tag
: false;
};
}

export const isArray = Array.isArray;
export const isMap = testTag('Map');
export const isSet = testTag('Set');
export function isMap(value) {
return value instanceof Map;
}
Comment on lines 38 to +41
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given isMap now gates proto-access control behavior in runtime.lookupProperty, it would be good to add a security regression test that a plain object spoofing [Symbol.toStringTag] = 'Map' is not treated as a Map and cannot be used to read blocked proto properties (e.g. constructor). No existing spec appears to cover the spoofing case.

Copilot uses AI. Check for mistakes.
export function isSet(value) {
return value instanceof Set;
}

// Older IE versions do not directly support indexOf so we must implement our own, sadly.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a regression test, something like

it('does not treat Symbol.toStringTag-spoofed objects as Map', function () {
    expectTemplate('{{value.constructor}}')
      .withInput({ value: { [Symbol.toStringTag]: 'Map', get: () => 'pwned' } })
      .toCompileTo(''); // or whatever the proto-controlled path produces
  });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add one each for isMap / isSet at the unit level (spec/utils.js already has the happy-path tests) plus an end-to-end runtime.js lookup test.

export function indexOf(array, value) {
Expand Down