You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IMPORTANT: Only the issue creator (@whyst0ne) is authorized to submit a PR for this issue. Any uninvited PRs from other accounts will be rejected and closed.
Overview
Entity indexing, dictionary lookup caches, and collection transformation in high-throughput API workflows require a defensive keyBy utility. Naive implementations are vulnerable to Prototype Pollution (CWE-1321) when untrusted collection keys evaluate to __proto__, constructor, or prototype, allowing arbitrary object modification. Additionally, unhandled iteratee exceptions trigger service crashes (CWE-755), sparse array traversals risk prototype leakage or denial-of-service (CWE-400), and non-array inputs cause unhandled type errors (CWE-1287). A defensive keyBy(array, iteratee, options) utility with prototype pollution defense, configurable collision strategies ('overwrite', 'keepFirst', 'ignore', 'error', custom resolver), custom error recovery (onError, suppressErrors), sparse array protection, and 100% unit test coverage is required.
Scope & Acceptance Criteria
Implement keyBy(array, iteratee, options) in apps/api/src/utils/keyBy.js.
Prototype pollution defense: safely reject or omit __proto__, constructor, and prototype (default 'skip', optional 'throw').
Configurable collision resolution: support 'overwrite', 'keepFirst', 'ignore', 'error', and custom resolver callbacks (prev, next, key) => val.
Custom iteratee error recovery: support onError hook and suppressErrors option collecting failed items under 'errors'.
Sparse array and non-array safety: check own properties to avoid prototype leakage in sparse arrays; safely handle non-arrays, primitives, and iterables.
Full unit test suite in apps/api/src/tests/keyBy.test.js validating 100% test pass rate via Node test runner.
Activity