From 656341e536714ca709f28a31c91c05655d9e7c15 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Wed, 4 Jul 2018 14:44:32 +0200 Subject: [PATCH] fix(files): ensure CID in `cat()` command is only cleaned when input is valid Fixes #799 License: MIT Signed-off-by: Pascal Precht pascal.precht@gmail.com --- src/files/cat.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/files/cat.js b/src/files/cat.js index ff468eb34..e78294e1f 100644 --- a/src/files/cat.js +++ b/src/files/cat.js @@ -4,6 +4,12 @@ const promisify = require('promisify-es6') const cleanCID = require('../utils/clean-cid') const v = require('is-ipfs') const bl = require('bl') +const CID = require('cids') + + +function checkValidInput(input) { + return (typeof input === 'string' && (v.cid(input) || v.ipfsPath(input))) || (Buffer.isBuffer(input) || CID.isCID(input)) +} module.exports = (send) => { return promisify((hash, opts, callback) => { @@ -13,7 +19,9 @@ module.exports = (send) => { } try { - hash = cleanCID(hash) + if (checkValidInput(hash)) { + hash = cleanCID(hash) + } } catch (err) { if (!v.ipfsPath(hash)) { return callback(err)