Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/pkg/utils/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function parseUserConfig(code: string): UserConfig | undefined {
}

const configs = config[1].trim().split(/[-]{3,}/);
const ret: UserConfig = {};
const ret = Object.create(null) as UserConfig;

const sortSet = new Set<string>();

Expand All @@ -20,6 +20,12 @@ export function parseUserConfig(code: string): UserConfig | undefined {
}
// 验证是否符合分组规范:group -> config -> properties
for (const [groupKey, groupValue] of Object.entries(obj)) {
// Reject keys inherited from Object.prototype (e.g. __proto__, constructor,
// valueOf, toString) so untrusted userscript metadata can't pollute lookups.
if (Reflect.has(Object.prototype, groupKey)) {
throw new Error(`UserConfig key "${groupKey}" is not valid.`);
}

if (!groupValue || typeof groupValue !== "object") {
// 如果分组值不是对象,说明不符合规范
throw new Error(`UserConfig group "${groupKey}" is not a valid object.`);
Expand Down
Loading