infobyte / faraday

Open Source Vulnerability Management Platform
https://www.faradaysec.com
GNU General Public License v3.0
5.03k stars 915 forks source link

initial workspace creation fails if ~/.faraday/report directory doesn't exist #337

Closed bbirkinbine closed 1 year ago

bbirkinbine commented 5 years ago

This is the error in the Web UI: {"data":"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n","status":500,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"url":"http://localhost:5985/_api/v2/ws/","data":{"_id":"testname","customer":"","name":"testname","type":"Workspace","children":[],"duration":{"start_date":1546405200000,"end_date":1546578000000},"scope":["target"],"description":"testdescription"},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":"INTERNAL SERVER ERROR"}

This is the error with faraday-server.py in debug mode: 2019-01-31 05:43:47,197 - faraday-server.server.web - INFO {MainThread} [web.py:170 - run() ] Faraday Server is ready /opt/faraday-python2-venv/lib/python2.7/site-packages/twisted/web/wsgi.py:128: UnicodeWarning: write() argument should be str, not u'[2019-01-31 05:47:00,776] ERROR in app: Exception on /v2/ws/ [POST]\nTraceback (most recent call last):\n File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app\n response = self.full_dispatch_request()\n File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request\n rv = self.handle_user_exception(e)\n File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception\n reraise(exc_type, exc_value, tb)\n File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request\n rv = self.dispatch_request()\n File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request\n return self.view_functions[rule.endpoint](**req.view_args)\n File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask_classful.py", line 268, in proxy\n response = view(**request.view_args)\n File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask_classful.py", line 239, in inner\n return fn(*args, **kwargs)\n File "/home/vagrant/dist/faraday-dev/server/api/base.py", line 604, in post\n created = self._perform_create(data, **kwargs)\n File "/home/vagrant/dist/faraday-dev/server/api/modules/workspaces.py", line 181, in _perform_create\n self._createWorkspaceFolder(workspace.name)\n File "/home/vagrant/dist/faraday-dev/server/api/modules/workspaces.py", line 192, in _createWorkspaceFolder\n os.mkdir(self._report_path)\nOSError: [Errno 2] No such file or directory: \'/home/vagrant/.faraday/report/testname\'\n' (unicode) data, type(data).__name__), category=UnicodeWarning) 2019-01-31 05:47:00,776 - flask.app - ERROR {PoolThread-twisted.internet.reactor-2} [app.py:1761 - log_exception() ] Exception on /v2/ws/ [POST] Traceback (most recent call last): File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask_classful.py", line 268, in proxy response = view(**request.view_args) File "/opt/faraday-python2-venv/lib/python2.7/site-packages/flask_classful.py", line 239, in inner return fn(*args, **kwargs) File "/home/vagrant/dist/faraday-dev/server/api/base.py", line 604, in post created = self._perform_create(data, **kwargs) File "/home/vagrant/dist/faraday-dev/server/api/modules/workspaces.py", line 181, in _perform_create self._createWorkspaceFolder(workspace.name) File "/home/vagrant/dist/faraday-dev/server/api/modules/workspaces.py", line 192, in _createWorkspaceFolder os.mkdir(self._report_path) OSError: [Errno 2] No such file or directory: '/home/vagrant/.faraday/report/testname'

bbirkinbine commented 5 years ago

Fix appears to be the following:

server/api/modules/workspaces.py:192 if not os.path.exists(self._report_path): os.mkdir(self._report_path)

recommend changing os.mkdir to os.makedirs so that intermediate directories will be made automatically

llazzaro commented 5 years ago

Hi! This issue was solved by our side. However I prefer to use mkdirs (with the "s"). I will keep open this issue until we merge the pr. Thanks