Skip to content

Commit fbbb681

Browse files
committed
fix(dashboard): harden config selector paths
1 parent 19c029e commit fbbb681

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

dashboard/src/components/shared/AstrBotConfigV4.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,16 @@ let currentEditingKeyIterable = null
8787
function getValueBySelector(obj, selector) {
8888
const keys = selector.split('.')
8989
let current = obj
90+
9091
for (const key of keys) {
91-
if (current && typeof current === 'object' && key in current) {
92+
if (['__proto__', 'prototype', 'constructor'].includes(key)) {
93+
return undefined
94+
}
95+
if (
96+
current &&
97+
typeof current === 'object' &&
98+
Object.prototype.hasOwnProperty.call(current, key)
99+
) {
92100
current = current[key]
93101
} else {
94102
return undefined
@@ -104,14 +112,21 @@ function setValueBySelector(obj, selector, value) {
104112
// 创建嵌套对象路径
105113
for (let i = 0; i < keys.length - 1; i++) {
106114
const key = keys[i]
115+
if (['__proto__', 'prototype', 'constructor'].includes(key)) {
116+
return
117+
}
107118
if (!current[key] || typeof current[key] !== 'object') {
108119
current[key] = {}
109120
}
110121
current = current[key]
111122
}
112123
113124
// 设置最终值
114-
current[keys[keys.length - 1]] = value
125+
const lastKey = keys[keys.length - 1]
126+
if (['__proto__', 'prototype', 'constructor'].includes(lastKey)) {
127+
return
128+
}
129+
current[lastKey] = value
115130
}
116131
117132
// 创建一个计算属性来处理 JSON selector 的获取和设置

0 commit comments

Comments
 (0)