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

Commit 41ef542

Browse files
committed
Sanitize multihash input to Exporter.
1 parent 879f9a8 commit 41ef542

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@
5454
},
5555
"dependencies": {
5656
"block-stream2": "^1.1.0",
57+
"bs58": "^3.0.0",
5758
"debug": "^2.2.0",
5859
"field-trip": "0.0.2",
5960
"ipfs-merkle-dag": "^0.5.0",
6061
"ipfs-unixfs": "^0.1.0",
62+
"is-ipfs": "^0.2.0",
6163
"isstream": "^0.1.2",
6264
"readable-stream": "^1.1.13",
6365
"run-series": "^1.1.4",

src/exporter.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const debug = require('debug')
44
const log = debug('exporter')
55
log.err = debug('exporter:error')
6+
const isIPFS = require('is-ipfs')
7+
const bs58 = require('bs58')
68
const UnixFS = require('ipfs-unixfs')
79
const series = require('run-series')
810
const Readable = require('readable-stream').Readable
@@ -19,6 +21,14 @@ function Exporter (hash, dagService, options) {
1921
return new Exporter(hash, dagService, options)
2022
}
2123

24+
// Sanitize hash.
25+
if (!isIPFS.multihash(hash)) {
26+
throw new Error('not valid multihash')
27+
}
28+
if (Buffer.isBuffer(hash)) {
29+
hash = bs58.encode(hash)
30+
}
31+
2232
Readable.call(this, { objectMode: true })
2333

2434
this.options = options || {}

0 commit comments

Comments
 (0)