{"record":{"id":"cc11e5f4209dbcf6","repo":"kovidgoyal/kitty","slug":"malformed-osc-5522-read-request-payload-is-not-va","errorCode":null,"errorMessage":"Malformed OSC 5522: read request payload is not valid base64 encoded UTF-8. Error: {e}","messagePattern":"Malformed OSC 5522: read request payload is not valid base64 encoded UTF-8\\. Error: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kitty/clipboard.py","lineNumber":414,"sourceCode":"            try:\n                k, v = record.split('=', 1)\n            except Exception:\n                log_error('Malformed OSC 5522: metadata is not key=value pairs')\n                return\n            m[k] = v\n        typ = m.get('type', '')\n        try:\n            m = {k: decode_metadata_value(k, v) for k, v in m.items()}\n        except Exception as e:\n            log_error(f'Malformed OSC 5522: could not decode a metadata value. Error: {e}')\n            if typ in ('wdata', 'walias') and self.in_flight_write_request is not None:\n                self.abort_write_request(self.in_flight_write_request, 'EINVAL')\n            return\n        if typ == 'read':\n            try:\n                mime_types = tuple(strict_base64_decode(epayload).decode('utf-8').split())\n            except Exception as e:\n                log_error(f'Malformed OSC 5522: read request payload is not valid base64 encoded UTF-8. Error: {e}')\n                return\n            rr = ReadRequest(\n                is_primary_selection=m.get('loc', '') == 'primary',\n                mime_types=mime_types,\n                protocol_type=ProtocolType.osc_5522,\n                id=sanitize_id(m.get('id', '')),\n                human_name=m.get('name', ''),\n                password=m.get('pw', ''),\n            )\n            self.handle_read_request(rr)\n        elif typ == 'write':\n            self.in_flight_write_request = WriteRequest(\n                is_primary_selection=m.get('loc', '') == 'primary',\n                protocol_type=ProtocolType.osc_5522,\n                id=sanitize_id(m.get('id', '')),\n                human_name=m.get('name', ''),\n                password=m.get('pw', ''),\n            )","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/clipboard.py#L396-L432","documentation":"An OSC 5522 read request's payload (the list of MIME types) failed strict base64 decode or UTF-8 decode; the request is dropped.","triggerScenarios":"typ=read with epayload that is not strict base64 of UTF-8, e.g. raw 'text/plain' sent unencoded.","commonSituations":"Clients forgetting that the read-request payload must be base64-encoded; protocol experiments.","solutions":["Encode the MIME list as base64 UTF-8 before sending","Verify with kitty's clipboard protocol documentation"],"exampleFix":"# before\n\\x1b]5522;type=read\\x1b]5522;text/plain\\x1b\\\\\n# after\n\\x1b]5522;type=read\\x1b]5522;dGV4dC9wbGFpbg==\\x1b\\\\","handlingStrategy":"validation","validationCode":"import base64\ndef encode_mimes(mimes):\n    return base64.b64encode(' '.join(mimes).encode()).decode()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never send raw MIME strings in read requests — always base64 them","Validate payload with strict b64decode before writing to the pty"],"tags":["kitty","clipboard","osc5522","base64","read-request"],"backgroundTag":"base64-decode-invalid-input","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}