Check for binary files

master
Joe Biellik 4 years ago
parent d27c32abf1
commit 42f53c2bae

@ -1,5 +1,6 @@
const config = require('config');
const fs = require('fs').promises;
const isBinaryFile = require('isbinaryfile').isBinaryFile;
const Paste = require('../models/paste');
module.exports = {
@ -40,7 +41,12 @@ module.exports = {
path = ctx.request.files.paste.path;
}
ctx.request.body.paste = await fs.readFile(path);
const data = await fs.readFile(path);
const stat = await fs.lstat(path);
if (isBinaryFile(data, stat.size)) ctx.throw();
ctx.request.body.paste = data;
try {
await fs.unlink(path);

5
package-lock.json generated

@ -1457,6 +1457,11 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"isbinaryfile": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.6.tgz",
"integrity": "sha512-ORrEy+SNVqUhrCaal4hA4fBzhggQQ+BaLntyPOdoEiwlKZW9BZiJXjg3RMiruE4tPEI3pyVPpySHQF/dKWperg=="
},
"isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",

@ -24,6 +24,7 @@
"dependencies": {
"bytes": "^3.1.0",
"config": "^3.3.1",
"isbinaryfile": "^4.0.6",
"koa": "^2.13.0",
"koa-body": "^4.2.0",
"koa-compress": "^5.0.1",

Loading…
Cancel
Save