Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 656341e

Browse files
committed
fix(files): ensure CID in cat() command is only cleaned when input is valid
Fixes #799 License: MIT Signed-off-by: Pascal Precht [email protected]
1 parent 6413fa1 commit 656341e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/files/cat.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ const promisify = require('promisify-es6')
44
const cleanCID = require('../utils/clean-cid')
55
const v = require('is-ipfs')
66
const bl = require('bl')
7+
const CID = require('cids')
8+
9+
10+
function checkValidInput(input) {
11+
return (typeof input === 'string' && (v.cid(input) || v.ipfsPath(input))) || (Buffer.isBuffer(input) || CID.isCID(input))
12+
}
713

814
module.exports = (send) => {
915
return promisify((hash, opts, callback) => {
@@ -13,7 +19,9 @@ module.exports = (send) => {
1319
}
1420

1521
try {
16-
hash = cleanCID(hash)
22+
if (checkValidInput(hash)) {
23+
hash = cleanCID(hash)
24+
}
1725
} catch (err) {
1826
if (!v.ipfsPath(hash)) {
1927
return callback(err)

0 commit comments

Comments
 (0)