benzino77 / clamav-rest-api

ClamAV REST API. Scan files using simple POST request.
MIT License
127 stars 44 forks source link

TypeError: req.files.hasOwnProperty is not a function #44

Closed xvisionbelgium closed 1 year ago

xvisionbelgium commented 1 year ago

Environment : NodeJS v16.18.1 on CentOS 7

We are getting the error when postng a file. Any idea how to fix this ?

/home/xvision/node/clamav-rest-api/src/utils/checkParams.js:20 const hasProperKey = req.files.hasOwnProperty(process.env.APP_FORM_KEY);

TypeError: req.files.hasOwnProperty is not a function at checkParams (/home/xvision/node/clamav-rest-api/src/utils/checkParams.js:20:34) at /home/xvision/node/clamav-rest-api/src/routes/scan.js:10:24 at Layer.handle [as handle_request] (/home/xvision/node/clamav-rest-api/node_modules/express/lib/router/layer.js:95:5) at next (/home/xvision/node/clamav-rest-api/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/home/xvision/node/clamav-rest-api/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/home/xvision/node/clamav-rest-api/node_modules/express/lib/router/layer.js:95:5) at /home/xvision/node/clamav-rest-api/node_modules/express/lib/router/index.js:284:15 at Function.process_params (/home/xvision/node/clamav-rest-api/node_modules/express/lib/router/index.js:346:12) at next (/home/xvision/node/clamav-rest-api/node_modules/express/lib/router/index.js:280:10) at Function.handle (/home/xvision/node/clamav-rest-api/node_modules/express/lib/router/index.js:175:3)

benzino77 commented 1 year ago

What is a value set for APP_FORM_KEY in your .env (or in your environemnt) and how do you make a POST call to CRA?

benzino77 commented 1 year ago

Have you run npm install in your CRA directory as stated in the README?

xvisionbelgium commented 1 year ago

Yes, did the following Cloned the repo Npm install Npm start

.env file is the following

NODE_ENV=production

APP_PORT=3000 APP_FORM_KEY=FILES APP_MORGAN_LOG_FORMAT=combined APP_MAX_FILE_SIZE=26214400 APP_MAX_FILES_NUMBER=4

CLAMD_IP=127.0.0.1 CLAMD_PORT=3310 CLAMD_TIMEOUT=30000 You can also start clamav-rest-api by cloning the repo and run commands listed below: npm install npm install -D # if you want to run tests or examples

Configuration described below - needed before start app

npm start

From: benzino77 @.> Sent: Wednesday, January 25, 2023 2:42 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

Have you run npm install in your CRA directory as stated in the READMEhttps://github.com/benzino77/clamav-rest-api#how-to-start-clamav-rest-api?

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403639239, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZ7DETMQP77PGP7LSIDWUEUSFANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

xvisionbelgium commented 1 year ago

If I comment out the test in the code, the scanning works file

From: benzino77 @.> Sent: Wednesday, January 25, 2023 2:38 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

What is a value set for APP_FORM_KEY in your .env (or in your environemnt) and how do you make a POST call to CRA?

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403635174, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZY6FDJ7Y5A4CVVV7YTWUEUFBANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

benzino77 commented 1 year ago

Which line/lines do you comment out?

xvisionbelgium commented 1 year ago

/ const hasProperKey = req.files.hasOwnProperty(process.env.APP_FORM_KEY); if (!hasProperKey || passedFilesLength > 1) { return invalidFormKeyError; } /

In checkParams.js

From: benzino77 @.> Sent: Wednesday, January 25, 2023 2:50 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

Which line/lines do you comment out?

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403655327, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZ7QPDAIVEFZ2TACO23WUEVR3ANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

xvisionbelgium commented 1 year ago

Hi

APP_FORM_KEY is FILES as default I’ve debugged (with console.write) the values and they seem correct

From: benzino77 @.> Sent: Wednesday, January 25, 2023 2:38 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

What is a value set for APP_FORM_KEY in your .env (or in your environemnt) and how do you make a POST call to CRA?

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403635174, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZY6FDJ7Y5A4CVVV7YTWUEUFBANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

benzino77 commented 1 year ago

How do you make a POST call to CRA?

xvisionbelgium commented 1 year ago

I‘m testing with Postman

@.***

From: benzino77 @.> Sent: Wednesday, January 25, 2023 2:54 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

How do you make a POST call to CRA?

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403659543, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZ6DSGUUAUUUY4VKLXTWUEV55ANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

benzino77 commented 1 year ago

How do you set Postman "Body tab"

xvisionbelgium commented 1 year ago

Seems that my screenshot that I’ve added came not through… Set up like described in your README.md

Screenshot : https://1drv.ms/u/s!AiMpBVIUzr5T33OmZ1pfAcvJGErK?e=AbaZE9

From: benzino77 @.> Sent: Wednesday, January 25, 2023 3:01 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

How do you set Postman "Body tab"

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403668769, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZ24OB4KG5G2H6Q6YHDWUEWYZANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

xvisionbelgium commented 1 year ago

If I dump req.files object ( console.write(req.files) )

req.files DUMP

[Object: null prototype] { FILES: { name: 'eicar.com', data: <Buffer 58 35 4f 21 50 25 40 41 50 5b 34 5c 50 5a 58 35 34 28 50 5e 29 37 43 43 29 37 7d 24 45 49 43 41 52 2d 53 54 41 4e 44 41 52 44 2d 41 4e 54 49 56 49 52 ... 18 more bytes>, size: 68, encoding: '7bit', tempFilePath: '', truncated: false, mimetype: 'application/x-msdownload', md5: '44d88612fea8a8f36de82e1278abb02f', mv: [Function: mv] } }

From: benzino77 @.> Sent: Wednesday, January 25, 2023 3:01 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

How do you set Postman "Body tab"

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403668769, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZ24OB4KG5G2H6Q6YHDWUEWYZANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

benzino77 commented 1 year ago

That is strange. I cannot reproduce your problem. Try to delete node_modules directory (or do a fresh clone of the repo) run npm install and try again. Screenshot from 2023-01-25 17-07-16

benzino77 commented 1 year ago

Hint: do not upgrade express-filesupload package.

xvisionbelgium commented 1 year ago

Tried it… same problem

From: benzino77 @.> Sent: Wednesday, January 25, 2023 5:15 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

That is strange. I cannot reproduce your problem. Try to delete node_modules directory (or do a fresh clone of the repo) run npm install and try again. [Screenshot from 2023-01-25 17-07-16]https://user-images.githubusercontent.com/15658235/214615920-e1c92d9a-f132-4ac9-bdd4-cce1c59adb45.png

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403865378, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZ2UQ3JY5NTYJIIEDQLWUFGO3ANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

xvisionbelgium commented 1 year ago

This seems to do the trick… forced it to v1.1.9 But now I got a extra vulnerability warning…

From: benzino77 @.> Sent: Wednesday, January 25, 2023 5:44 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

Hint: do not upgrade express-filesupload package.

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403910152, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZ5UQC3P4F6CIGXSZATWUFJ6PANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

benzino77 commented 1 year ago

If you are using CRA as it is, you don't have to "force" anything. That is what package*.json files are for. To install proper versions of libraries for a project.

xvisionbelgium commented 1 year ago

It breaks if express-fileupload is 1.3.0 or higher 1.2.1 works fine

From: benzino77 @.> Sent: Wednesday, January 25, 2023 6:02 PM To: benzino77/clamav-rest-api @.> Cc: Johan Hamelinck (XV) @.>; Author @.> Subject: Re: [benzino77/clamav-rest-api] TypeError: req.files.hasOwnProperty is not a function (Issue #44)

If you are using CRA as it is, you don't have to "force" anything. That is what package*.json files are for. To install proper versions of libraries for a project.

— Reply to this email directly, view it on GitHubhttps://github.com/benzino77/clamav-rest-api/issues/44#issuecomment-1403936385, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIWYDZ7CQTP32KJMHRLQ4YTWUFL6ZANCNFSM6AAAAAAUGI7J4M. You are receiving this because you authored the thread.Message ID: @.**@.>>

benzino77 commented 1 year ago

You can pull the latest version of CRA which is using latest express-fileupload.