Giter VIP home page Giter VIP logo

flask-file-server's Introduction

#flask-file-server

A flask file server with an elegant frontend for browsing, uploading and streaming files

screenshot

Build

docker build --rm -t maaydin/flask-file-server:latest .

Run

docker run -p 8000:8000 maaydin/flask-file-server

Params

FS_BIND = Param for bind address, default 0.0.0.0
FS_PORT = Param for server port, default 8000
FS_PATH = Param for serve path, default /tmp
FS_KEY = Param for authentication key as base64 encoded username:password, default none

docker run -p 8000:8000 -e FS_BIND=0.0.0.0 -e FS_PORT=8000 -e FS_PATH=/tmp -e FS_KEY=dGVzdDp0ZXN0 maaydin/flask-file-server

flask-file-server's People

Contributors

atridis avatar maaydin avatar wildog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-file-server's Issues

timestamp issue

Hi, thank you for the great flask file server, and I found an issue about timestamp of modified time. According to code, the timestamp is based on utc time, however, I think the timestamp should be same with the system time of operating system.

My time zone is UTC+8, and there's wrong time(UTC) show in my file server.

So I think the code can be modified from

mdate = datetime.utcfromtimestamp(timestamp)

to

mdate = datetime.fromtimestamp(timestamp)

I am not sure that my idea is right or wrong, or there's some reason that you use utc time?

Thank you.

ImportError: cannot import name secure_filename

i got this error when starting the container

Traceback (most recent call last):
  File "./file_server.py", line 3, in <module>
    from werkzeug import secure_filename
ImportError: cannot import name secure_filename

how to reproduce:
docker run -p 8000:8000 maaydin/flask-file-server

Macbook Pro M1 Big Sur 11.4

Files are not streaming

I have tried opening music files and video files, although they can be downloaded as using the save as option, they are not being able to be streamed. How do i solve this issue?

Uploading any file gives "Error: undefined" in the upload window

Using Python3 and this code, everything works fine. Starts ok, no errors but whenever I use it to upload a file I click "add file", Select a file and the progress bar goes to 100% then immediately under it it says "Error: Undefined" and sits there. If I click on "Close" I'm taken back to the file view and the uploaded file doesn't show until I click "Reload" in my browser.

Browser: Latest Chrome.
OS: Tested on windows and Linux 18.04
Python: Python 3.6.5

Screenshot attached

screenshot from 2018-05-03 11-15-31

login

what is the use of login... top tight

Security Vulnerability Found

Absolute Path Traversal due to incorrect use of send_file call

A path traversal attack (also known as directory traversal) aims to access files and directories that are stored outside the web root folder. By manipulating variables that reference files with “dot-dot-slash (../)” sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system including application source code or configuration and critical system files. This attack is also known as “dot-dot-slash”, “directory traversal”, “directory climbing” and “backtracking”.

Common Weakness Enumeration category

CWE - 36

Root Cause Analysis

The os.path.join call is unsafe for use with untrusted input. When the os.path.join call encounters an absolute path, it ignores all the parameters it has encountered till that point and starts working with the new absolute path. Please see the example below.

>>> import os.path
>>> static = "path/to/mySafeStaticDir"
>>> malicious = "/../../../../../etc/passwd"
>>> os.path.join(t,malicious)
'/../../../../../etc/passwd'

Since the "malicious" parameter represents an absolute path, the result of os.path.join ignores the static directory completely. Hence, untrusted input is passed via the os.path.join call to flask.send_file can lead to path traversal attacks.

In this case, the problems occurs due to the following code :

res = send_file(path)

Here, the p parameter is attacker controlled. This parameter passes through the unsafe os.path.join call making the effective directory and filename passed to the send_file call attacker controlled. This leads to a path traversal attack.

Proof of Concept

The bug can be verified using a proof of concept similar to the one shown below.

curl --path-as-is 'http://<domain>////../../../../etc/passwd"'

Remediation

This can be fixed by preventing flow of untrusted data to the vulnerable send_file function. In case the application logic necessiates this behaviour, one can either use the werkzeug.utils.safe_join to join untrusted paths or replace flask.send_file calls with flask.send_from_directory calls.

Common Vulnerability Scoring System Vector

The attack can be carried over the network. A complex non-standard configuration or a specialized condition is not required for the attack to be successfully conducted. There is no user interaction required for successful execution. The attack can affect components outside the scope of the target module. The attack can be used to gain access to confidential files like passwords, login credentials and other secrets. It cannot be directly used to affect a change on a system resource. Hence has limited to no impact on integrity. Using this attack vector a attacker may make multiple requests for accessing huge files such as a database. This can lead to a partial system denial service. However, the impact on availability is quite low in this case. Taking this account an appropriate CVSS v3.1 vector would be

(AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:L)[https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator?vector=AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:L&version=3.1]

This gives it a base score of 9.3/10 and a severity rating of critical.

References

This bug was found using CodeQL by Github

Cound not delete files

Woulld you please tell me how to delete file using this app? I cound not find anywhere to delete files...

Here is my homepage:
image

BUG

My env is win10 pychram

I have add # * coding:utf-8 * in head of file_server.py

then issue in chrome under win10
http://127.0.0.1:8000/

File "D:\Anaconda2\lib\site-packages\jinja2\filters.py", line 136, in do_lower
return soft_unicode(s).lower()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa1 in position 0: ordinal not in range(128)
127.0.0.1 - - [28/Nov/2017 19:23:17] "GET / HTTP/1.1" 500 -

[2017-11-28 19:23:17,599] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "D:\Anaconda2\lib\site-packages\flask\app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.