Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 76387a2

Browse files
butlerxWardormeur
authored andcommitted
check if image is jpeg, png or gif (#202)
1 parent 88609f3 commit 76387a2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

profiles.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,11 @@ module.exports = function (options) {
798798
if (!_.contains(args.fileType, 'image')) return done(null, {ok: false, why: 'Avatar upload: file must be an image.'});
799799
if (file.length > 5242880) return done(null, {ok: false, why: 'Avatar upload: max file size of 5MB exceeded.'});
800800

801+
var buf = new Buffer(file, 'base64');
802+
var type = buf.toString('hex', 0, 4);
803+
var types = ['ffd8ffe0', '89504e47', '47494638'];
804+
if (!_.contains(types, type)) return done(null, {ok: false, why: 'Avatar upload: file must be an image of type png, jpeg or gif.'});
805+
801806
// pg conf properties
802807
options.postgresql.database = options.postgresql.name;
803808
options.postgresql.user = options.postgresql.username;
@@ -832,8 +837,6 @@ module.exports = function (options) {
832837
return;
833838
}
834839

835-
var buf = new Buffer(file, 'base64');
836-
837840
stream.write(buf, 'base64', function () {
838841
stream.end();
839842
});

0 commit comments

Comments
 (0)