/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/utils/set.ts
39 строк
918 B
Copilot
🐚 harden `get()` against prototype-path traversal (`__proto__` / `constructor` / `prototype`) (#13479)
25 май 2026, 06:23
Не верифицирован
25 май 2026, 06:23
6aa81f9
Код
Авторство
О чём код?
import { PROTOTYPE_KEYWORDS } from '../constants'; import type { FieldPath, FieldValues } from '../types'; import isKey from './isKey'; import isObject from './isObject'; import stringToPath from './stringToPath'; export default ( object: FieldValues, path: FieldPath<FieldValues>, value?: unknown, ) => { let index = -1; const tempPath = isKey(path) ? [path] : stringToPath(path); const length = tempPath.length; const lastIndex = length - 1; while (++index < length) { const key = tempPath[index]; let newValue = value; if (index !== lastIndex) { const objValue = object[key]; newValue = isObject(objValue) || Array.isArray(objValue) ? objValue : !isNaN(+tempPath[index + 1]) ? [] : {}; } if (PROTOTYPE_KEYWORDS.includes(key)) { return; } object[key] = newValue; object = object[key]; } };