function setPath(document, keyPath, value) {
    if (!document) {
        throw new Error('No document was provided.');
    } else if (!keyPath) {
        throw new Error('No keyPath was provided.');
    }

    // If this is clearly a prototype pollution attempt, then refuse to modify the path
    if (keyPath.startsWith('__proto__') || keyPath.startsWith('constructor')) {
        return document;
    }

    return _setPath(document, keyPath, value);
}