sveltejs/kit · warning

Invalid key "${key}": This key is not allowed to prevent pro

Error message

Invalid key "${key}": This key is not allowed to prevent prototype pollution.

What it means

Form field paths are set into a nested object; keys named __proto__, constructor, or prototype could pollute Object.prototype. check_prototype_pollution rejects these keys outright to keep untrusted form input from corrupting object prototypes.

Source

Thrown at packages/kit/src/runtime/form-utils.js:495

	if (!path_regex.test(path)) {
		throw new Error(
			`Invalid field name ${path}` +
				(DEV
					? ': field names are written in JS object notation, so keys that would need quoting are not supported. See https://svelte.dev/docs/kit/remote-functions#form-Fields'
					: '')
		);
	}

	return path.split(/\.|\[|\]/).filter(Boolean);
}

/**
 * Check if a property key is dangerous and could lead to prototype pollution
 * @param {string} key
 */
function check_prototype_pollution(key) {
	if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
		throw new Error(
			`Invalid key "${key}"` +
				(DEV ? ': This key is not allowed to prevent prototype pollution.' : '')
		);
	}
}

/**
 * Sets a value in a nested object using an array of keys, mutating the original object.
 * @param {Record<string, any>} object
 * @param {string[]} keys
 * @param {any} value
 */
export function deep_set(object, keys, value) {
	let current = object;

	for (let i = 0; i < keys.length - 1; i += 1) {
		const key = keys[i];

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Remove or rename the offending field — never accept __proto__/constructor/prototype as field names.
  2. Validate/allowlist field names on the server before processing the submission.
  3. If the key is legitimately needed, store it under a safe name (e.g. data.constructorName) and document the mapping.

Example fix

// before
fields.as('__proto__');
// after
fields.as('proto_override');
Defensive patterns

Strategy: validation

Validate before calling

const DANGEROUS = new Set(['__proto__', 'constructor', 'prototype']);
if (name.split(/[.\[\]]/).some((seg) => DANGEROUS.has(seg))) {
  throw new Error(`field name contains forbidden key: ${name}`);
}

Prevention

When it happens

Trigger: A form posts a field named __proto__.x, constructor, or prototype[...]; an attacker crafts field names to reach deep_set with dangerous segments.

Common situations: Malicious or fuzzed submissions targeting the form parser; echoing user-controlled field names back into the form; generic template forms that accept arbitrary key names.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/150132ea5a1149e5. Report an issue: GitHub.