Giter VIP home page Giter VIP logo

codingforentrepreneurs / opencv-rest-api Goto Github PK

View Code? Open in Web Editor NEW
101.0 5.0 48.0 1.82 MB

Learn to create a REST API microservice for extracting faces from images using OpenCV, OpenCV-python, Flask, Docker, and Heroku

Home Page: https://cfe.sh/projects/opencv-rest-api

Python 83.21% PowerShell 0.24% Shell 3.84% Dockerfile 12.70%
flask opencv opencv-python docker dockerfile heroku tutorial cfe

opencv-rest-api's Introduction

opencv-rest-api's People

Contributors

codingforentrepreneurs 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

opencv-rest-api's Issues

[Security] Path Traversal Vulnerability found

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. It should be noted that access to files is limited by system operational access control (such as in the case of locked or in-use files on the Microsoft Windows operating system).

This attack is also known as “dot-dot-slash”, “directory traversal”, “directory climbing” and “backtracking”.

Root Cause Analysis

In this case, the path traversal vulnerability can be blamed on incorrect usage of the send_from_directory Flask call. The vulnerability occurs due to the code snippet shown below

@app.route("/static/outputs/<path:path>")
def static_outputs_view(path):
# path => Users/cfe/Dev/opencv-rest-api/api/storage/output/15/main.jpg
dirname = os.path.dirname(path)
if not dirname.startswith("/"):
dirname = f"/{dirname}"
filename = os.path.basename(path)
print(dirname, filename)
return send_from_directory(dirname, filename)

Here, since the path parameter is attacker controlled, the effective directory and filename passed to the send_from_directory call can be controlled by the attacker leading to a path traversal attack.

This can be exploited by accessing a URI like /static/outputs/../../../../etc/passwd which will return the contents of the /etc/passwd file.

Remediation

This can be easily fixed my restricting the value of file and path parameters by a fixed whitelist of possible values.

CVSS 3 Score

CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H

This bug was found using CodeQL by Github

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.