/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/utils/get.ts
32 строки
863 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 isKey from './isKey'; import isNullOrUndefined from './isNullOrUndefined'; import isObject from './isObject'; import isUndefined from './isUndefined'; import stringToPath from './stringToPath'; export default <T>( object: T, path?: string | null, defaultValue?: unknown, ): any => { if (!path || !isObject(object)) { return defaultValue; } const paths = isKey(path) ? [path] : stringToPath(path); if (paths.some((key) => PROTOTYPE_KEYWORDS.includes(key))) { return defaultValue; } const result = paths.reduce<any>((result, key) => { return isNullOrUndefined(result) ? undefined : result[key]; }, object); return isUndefined(result) || result === object ? isUndefined(object[path as keyof T]) ? defaultValue : object[path as keyof T] : result; };