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

Commit 2851761

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 2851761

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/files/cat.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ 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+
function checkValidInput (input) {
10+
return (typeof input === 'string' && (v.cid(input) || v.ipfsPath(input))) || (Buffer.isBuffer(input) || CID.isCID(input))
11+
}
712

813
module.exports = (send) => {
914
return promisify((hash, opts, callback) => {
@@ -13,7 +18,9 @@ module.exports = (send) => {
1318
}
1419

1520
try {
16-
hash = cleanCID(hash)
21+
if (checkValidInput(hash)) {
22+
hash = cleanCID(hash)
23+
}
1724
} catch (err) {
1825
if (!v.ipfsPath(hash)) {
1926
return callback(err)

0 commit comments

Comments
 (0)