Skip to content

new no watch PR - #6

Closed
davidka91 wants to merge 4 commits into
mainfrom
dev
Closed

new no watch PR#6
davidka91 wants to merge 4 commits into
mainfrom
dev

Conversation

@davidka91

Copy link
Copy Markdown
Owner

No description provided.

@davidka91

Copy link
Copy Markdown
Owner Author

🚨 Frogbot scanned this pull request and found the below:

📗 Scan Summary

  • Frogbot scanned for vulnerabilities and found 3 issues
Scan Category Status Security Issues
Software Composition Analysis ✅ Done
1 Issues Found 1 High
Contextual Analysis ✅ Done -
Static Application Security Testing (SAST) ✅ Done
2 Issues Found 1 High
1 Medium
Secrets ✅ Done -
Infrastructure as Code (IaC) ✅ Done Not Found

📦 Vulnerable Dependencies

Severity ID Contextual Analysis Direct Dependencies Impacted Dependency Fixed Versions
high (not applicable)
High
CVE-2023-30861 Not Applicable flask:2.2.2 flask 2.2.2 [2.2.5]
[2.3.2]

🔖 Details

Vulnerability Details

Jfrog Research Severity: Medium
Contextual Analysis: Not Applicable
Direct Dependencies: flask:2.2.2
Impacted Dependency: flask:2.2.2
Fixed Versions: [2.2.5], [2.3.2]
CVSS V3: 7.5

Persistent session cookies in Flask can lead to data leakage or privilege escalation when the application is hosted behind a caching proxy.

🔬 JFrog Research Details

Description:
Flask is a lightweight web framework for Python used for building web applications.
An issue arises when using a caching proxy that caches cookies (specifically, the Set-Cookie headers) from responses intended for clients. This situation can result in the proxy sending one client's session cookies to other clients, leading to data leakage or even privilege escalation.

The root cause of this issue is the absence of the Vary: Cookie header, which informs the proxy not to cache session cookies when the session is refreshed (i.e., resent to update the expiration) without being accessed or modified. The Vary: Cookie header is typically set when the session is accessed or modified.

To exploit this vulnerability, several specific conditions must be met:

  • The application must be hosted behind a proxy that caches responses along with their cookies.
  • The application must have the session.permanent attribute set to True.
  • The session must not be accessed or modified before the request is made.
  • The SESSION_REFRESH_EACH_REQUEST feature must be enabled (which is the default behavior).
  • The application should not set a Cache-Control header to indicate that a page is private and should not be cached.

Example of vulnerable code:

from flask import Flask, session

app = Flask(__name__)
app.secret_key = 'your_secret_key'

@app.route('/')
def index():
    session.permanent = True
    # Other code logic...
    return privateData(user)

In this example, a Flask application is used, and the session.permanent attribute is set to True. If this application is deployed behind a caching proxy without proper handling of session cookies and caching directives, the issue may be present.

Remediation:

Development mitigations

Add a Cache-Control in all requests/responses sent by the application explicitly instructing the caching proxy not to cache any content:

@app.after_request
def add_cache_control(response):
    response.headers['Cache-Control'] = 'no-store, no-cache, private, must-revalidate, max-age=0'
    return response
Development mitigations

Disable the SESSION_REFRESH_EACH_REQUEST setting of the Flask application:

app = Flask(__name__)
app.config['SESSION_REFRESH_EACH_REQUEST'] = False

def greet():
user_name = request.args.get('name', 'Guest')
# Rendering user input directly without escaping
return render_template_string(f"<h1>Hello, {user_name}!</h1>")

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Static Application Security Testing (SAST) Vulnerability

Severity Finding
high
High
Untrusted input is included in web page content
Full description

Vulnerability Details

Rule ID: python-xss

Overview

XSS, or Cross-Site Scripting, is a type of vulnerability that allows an attacker to
inject malicious code into a website or web application.
This can allow the attacker to steal sensitive information from users, such as their
cookies or login credentials, or to perform unauthorized actions on their behalf.

Query operation

In the query we look for any user input that flows into
a potential output of the application.

Vulnerable example

In the following example, the Flask application takes a user-supplied parameter (name)
from the query string and renders it directly into an HTML template using the
render_template_string function. The issue is that
the user input is not properly sanitized or escaped, making it vulnerable to XSS attacks.

from flask import Flask, request, render_template_string

app = Flask(__name__)

@app.route('/')
def index():
    name = request.args.get('name', 'Guest')
    message = f'Hello, {name}!'
    return render_template_string('<h1>{}</h1>'.format(message))

if __name__ == '__main__':
app.run()

An attacker can exploit this vulnerability by injecting malicious JavaScript code into the
name parameter. For instance, they could modify the URL to include the following payload:
http://localhost:5000/?name=<script>alert('XSS')</script>

Remediation

When rendering templates, use parametrized variable assignments (which are automatically
escaped) instead of direct string manipulation -

@app.route('/')
def index():
    name = request.args.get('name', 'Guest')
    message = f'Hello, {name}!'
-    return render_template_string('<h1>{}</h1>'.format(message))
+    return render_template_string('<h1>{{ message }}</h1>', message=message)
Code Flows
Vulnerable data flow analysis result

↘️ request.args (at Projects/python-fb-example/src/app.py line 8)

↘️ request.args.get('name', 'Guest') (at Projects/python-fb-example/src/app.py line 8)

↘️ user_name (at Projects/python-fb-example/src/app.py line 10)

↘️ f"<h1>Hello, {user_name}!</h1>" (at Projects/python-fb-example/src/app.py line 10)

↘️ render_template_string(f"<h1>Hello, {user_name}!</h1>") (at Projects/python-fb-example/src/app.py line 10)

↘️ return render_template_string(f"<h1>Hello, {user_name}!</h1>") (at Projects/python-fb-example/src/app.py line 10)





if __name__ == '__main__':
main()
app.run(debug=True)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Static Application Security Testing (SAST) Vulnerability

Severity Finding
medium
Medium
Flask web application is running in debug mode
Full description

Vulnerability Details

Rule ID: python-flask-debug

Overview

Debug mode in a Flask app is a feature that allows the developer to see detailed
error messages and tracebacks when an error occurs. This can be useful for debugging
and troubleshooting, but it can also create a security vulnerability if the app is
deployed in debug mode. In debug mode, Flask will display detailed error messages and
tracebacks to the user, even if the error is caused by malicious input.
This can provide attackers with valuable information about the app's internal workings
and vulnerabilities, making it easier for them to exploit those vulnerabilities.

Query operation

In this query we look Flask applications that set the debug argument to True

Vulnerable example

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run(debug=True)

In this example, the Flask application is set to run in debug mode by passing
debug=True as an argument to the app.run() function. This will make the application
emit potentially sensitive information to the users.

Remediation

When using app.run, omit the debug flag or set it to False -

if __name__ == '__main__':
-    app.run(debug=True)
+    app.run()



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant