{"record":{"id":"bd06ea7bbc9cebbd","repo":"ianstormtaylor/slate","slug":"cannot-set-the-key-property-of-the-selection","errorCode":null,"errorMessage":"Cannot set the \"${key}\" property of the selection!","messagePattern":"Cannot set the \"(.+?)\" property of the selection!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slate/src/interfaces/transforms/general.ts","lineNumber":316,"sourceCode":"\n        if (editor.selection == null) {\n          if (!(newProperties.anchor && newProperties.focus)) {\n            throw new Error(\n              `Cannot apply an incomplete \"set_selection\" operation properties ${Scrubber.stringify(\n                newProperties\n              )} when there is no current selection.`\n            )\n          }\n\n          editor.selection = { ...(newProperties as Range) }\n          break\n        }\n\n        const selection = { ...editor.selection }\n\n        for (const key in newProperties) {\n          if (NON_SETTABLE_SELECTION_PROPERTIES.includes(key)) {\n            throw new Error(\n              `Cannot set the \"${key}\" property of the selection!`\n            )\n          }\n\n          const value = newProperties[<keyof Range>key]\n\n          // Make sure we're not setting `then` to a function, since this will\n          // cause the selection to be treated as a Promise-like object, which\n          // can cause unexpected behaviour when returning the selection from\n          // async functions.\n          if (key === 'then' && typeof value === 'function') {\n            throw new Error(\n              'Cannot set the \"then\" property of the selection to a function'\n            )\n          }\n\n          if (value == null) {\n            if (key === 'anchor' || key === 'focus') {","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/ianstormtaylor/slate/blob/72a37c701e5da4bb13a305d416d9c070d19d3a45/packages/slate/src/interfaces/transforms/general.ts#L298-L334","documentation":"Thrown when a 'set_selection' operation tries to set a property that Slate forbids on selections (NON_SETTABLE_SELECTION_PROPERTIES, e.g. 'weight' from custom properties or internal keys). Slate only allows a defined subset of Range properties to be set on the selection to avoid corrupting internal state or prototype pollution-style keys.","triggerScenarios":"Transforms.setSelection(editor, { [forbiddenKey]: value }) where forbiddenKey is in NON_SETTABLE_SELECTION_PROPERTIES (e.g. 'weight', 'then'); applying a crafted or remote set_selection operation containing disallowed keys.","commonSituations":"Copying arbitrary custom keys onto selection in collaborative editors; untrusted/remote operation payloads being applied without sanitization; custom Range extensions colliding with reserved keys.","solutions":["Remove the disallowed key from the properties object passed to setSelection","Whitelist selection properties: only pass anchor, focus, mark, and other legitimate Range extension keys","Sanitize remote operation properties before applying them (strip keys in NON_SETTABLE_SELECTION_PROPERTIES)"],"exampleFix":"// before\nTransforms.setSelection(editor, { focus: p, weight: 1 } as any)\n\n// after\nTransforms.setSelection(editor, { focus: p })","handlingStrategy":"validation","validationCode":"const SETTABLE = new Set(['anchor','focus','mark']) // extend with your own\nconst safe: Partial<Range> = {}\nfor (const k in props) if (SETTABLE.has(k)) safe[k] = props[k]\nTransforms.setSelection(editor, safe)","typeGuard":"const isSettableSelectionKey = (k: string) =>\n  !NON_SETTABLE_SELECTION_PROPERTIES.includes(k) && k !== 'then'","tryCatchPattern":null,"preventionTips":["Build selection update objects with explicit keys, never spreads of unknown objects","Sanitize remote operation properties before applying","Keep custom Range extension keys out of reserved names"],"tags":["selection","forbidden-property","security","slate"],"backgroundTag":"forbidden-property-assignment","analyzedSha":"72a37c701e5da4bb13a305d416d9c070d19d3a45","analyzedAt":"2026-08-27T23:04:51.145Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}