{"record":{"id":"b1542ed1362ee0cc","repo":"can1357/oh-my-pi","slug":"enxio","errorCode":"ENXIO","errorMessage":"Refusing to download onto a special file: ${absolutePath}","messagePattern":"Refusing to download onto a special file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cursor.ts","lineNumber":186,"sourceCode":" * FIFO blocks until a reader arrives, so a `download_path` naming one would\n * hang the turn forever WITHOUT the non-regular check ever running — the open\n * itself never returns. Non-blocking turns that into `ENXIO` when no reader is\n * attached, and hands back a descriptor the `isFile()` check refuses when one\n * is. The flag has no effect on regular files, which is every legitimate\n * target.\n */\nasync function writeWithoutFollowingLinks(absolutePath: string, payload: string | Buffer): Promise<void> {\n\tawait fs.promises.mkdir(path.dirname(absolutePath), { recursive: true });\n\tconst handle = await fs.promises\n\t\t.open(\n\t\t\tabsolutePath,\n\t\t\tfs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK,\n\t\t)\n\t\t.catch((error: NodeJS.ErrnoException) => {\n\t\t\t// A readerless FIFO. Reported as the refusal it is, rather than the\n\t\t\t// bare \"no such device or address\" the errno spells out.\n\t\t\tif (error.code === \"ENXIO\") {\n\t\t\t\tthrow new Error(`Refusing to download onto a special file: ${absolutePath}`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t});\n\ttry {\n\t\tconst stat = await handle.stat();\n\t\tif (!stat.isFile()) {\n\t\t\tthrow new Error(`Refusing to download onto a non-regular file: ${absolutePath}`);\n\t\t}\n\t\tif (stat.nlink > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Refusing to download onto a file with ${stat.nlink} hard links, which would overwrite its other names: ${absolutePath}`,\n\t\t\t);\n\t\t}\n\t\tawait handle.truncate(0);\n\t\tawait handle.writeFile(payload);\n\t} finally {\n\t\tawait handle.close();\n\t}","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cursor.ts#L168-L204","documentation":"MCP resource downloads are written with O_NOFOLLOW|O_EXCL-style safety: the target must be a regular file, not a FIFO, device, socket, or other special inode. Opening a readerless FIFO with O_NONBLOCK fails with ENXIO, which this code re-reports explicitly as a refusal instead of the cryptic 'no such device or address'. It protects users from having a download clobber or block on a special file.","triggerScenarios":"Calling the resource-download path (readMcpResource with downloadPath) where the destination path is a named pipe (mkfifo), a device node, socket, or other non-regular special file.","commonSituations":"Pointing a download at an existing FIFO created for inter-process piping; a leftover pipe file in a download directory; trying to 'write through' a device like /dev/stdout.","solutions":["Remove the special file (`rm <path>`) and let the download create a fresh regular file.","Download to a different filename that does not already exist as a FIFO/device.","If the FIFO is in use by a reader, run the reader first, or don't route the download through the pipe."],"exampleFix":"// before: destination is a FIFO\n$ mkfifo /tmp/report.pdf  # download to /tmp/report.pdf -> ENXIO\n// after\n$ rm /tmp/report.pdf && retry the download to /tmp/report.pdf","handlingStrategy":"validation","validationCode":"import { stat } from \"node:fs/promises\";\nconst s = await stat(downloadPath).catch(() => null);\nif (s && !s.isFile()) throw new Error(`Refusing: ${downloadPath} is not a regular file`);","typeGuard":"function isRegularFile(s: { isFile(): boolean } | undefined): boolean {\n  return !!s && s.isFile();\n}","tryCatchPattern":"try {\n  await downloadResource(res, downloadPath);\n} catch (e) {\n  if (String(e.message).startsWith(\"Refusing to download onto a special file\")) {\n    // pick another destination or remove the FIFO first\n  } else throw e;\n}","preventionTips":["Never create FIFOs/devices in directories used as download targets.","Check `ls -l` file type (p/s/b/c) before reusing a path as a destination.","Prefer fresh, non-existent destination filenames for downloads."],"tags":["filesystem","security","mcp"],"backgroundTag":"special-file-write-refused","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}