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
14 changes: 11 additions & 3 deletions src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,30 @@ export class PawnProConfigManager {
const current = readJsonFile(filePath) ?? {};

const parts = dotPath.split('.');
if (parts.length === 0 || parts.some((p) => p.length === 0)) {
throw new Error('Invalid config key');
}

const isPollutionKey = (k: string): boolean =>
k === '__proto__' || k === 'constructor' || k === 'prototype';

let cursor: Record<string, unknown> = current;
for (let i = 0; i < parts.length - 1; i++) {
const key = parts[i];
// Validação no ponto de uso: a chave é checada imediatamente antes de
// indexar o objeto, bloqueando __proto__/constructor/prototype.
if (!isSafeKey(key)) {
if (!isSafeKey(key) || isPollutionKey(key)) {
throw new Error('Invalid config key: prototype pollution attempt');
}
if (!isPlainObject(cursor[key])) {

const hasOwn = Object.prototype.hasOwnProperty.call(cursor, key);
if (!hasOwn || !isPlainObject(cursor[key])) {
cursor[key] = {};
}
cursor = cursor[key] as Record<string, unknown>;
}
const leaf = parts[parts.length - 1];
if (!isSafeKey(leaf)) {
if (!isSafeKey(leaf) || isPollutionKey(leaf)) {
throw new Error('Invalid config key: prototype pollution attempt');
}
cursor[leaf] = value;
Expand Down
Loading