* Validates that a property name is safe to use * @param {string} propertyName - The property name to validate * @param {string} optionName - The option field name (for error message) * @throws {Error} If property name is dangerous
(propertyName, optionName)
| 65 | * @throws {Error} If property name is dangerous |
| 66 | */ |
| 67 | function validatePropertyName(propertyName, optionName) { |
| 68 | if (typeof propertyName !== 'string') { |
| 69 | return; // Only validate string property names |
| 70 | } |
| 71 | |
| 72 | const normalized = propertyName.toLowerCase(); |
| 73 | if (DANGEROUS_PROPERTY_NAMES.some(dangerous => normalized === dangerous.toLowerCase())) { |
| 74 | throw new Error( |
| 75 | `[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution` |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | if (criticalProperties.some(dangerous => normalized === dangerous.toLowerCase())) { |
| 80 | throw new Error( |
| 81 | `[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution` |
| 82 | ); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Normalizes processEntities option for backward compatibility |