Skip to content

Add Flask decorators for Cache-Control headers#36

Merged
ahosgood merged 1 commit into
mainfrom
feature/flask-cache-headers
May 14, 2026
Merged

Add Flask decorators for Cache-Control headers#36
ahosgood merged 1 commit into
mainfrom
feature/flask-cache-headers

Conversation

@ahosgood
Copy link
Copy Markdown
Member

No description provided.

@ahosgood ahosgood enabled auto-merge (squash) May 14, 2026 13:58
@wiz-2986343e2e
Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 3 Low
Software Management Finding Software Management Findings -
Total 3 Low

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

Pull Request Developer Guidance

If the link to the Wiz scan details doesn't work, please ensure you are using the right role in Wiz and that the repository is assigned to the correct project within our Wiz Terraform. Or, you can ask for help in #tna-cloud-security on Slack.

def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
response = make_response(f(*args, **kwargs))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Low SAST Finding

Unsafe Usage of flask.make_response() with Unescaped Content (CWE-79)

More Details

The flask.make_response() function is used to create a response object without properly escaping the content. If the response contains user-supplied data or untrusted content, it can lead to a Cross-Site Scripting (XSS) vulnerability. XSS vulnerabilities allow attackers to inject malicious scripts into web pages, which can lead to data theft, session hijacking, and other security risks.

When rendering HTML content, it is crucial to escape or sanitize any user-supplied data to prevent XSS attacks. Failing to do so can allow attackers to inject malicious scripts that will be executed in the user's browser, potentially compromising their data or session. The consequences of an XSS attack can be severe, including data theft, account takeover, and the spread of malware. To avoid this issue, use flask.render_template() for rendering HTML templates, as it automatically escapes user input. For returning data from an API, use flask.jsonify() instead.

Attribute Value
Impact Medium
Likelihood Low

Remediation

The flask.make_response() function in Flask can lead to cross-site scripting (XSS) vulnerabilities if the response content is not properly sanitized or escaped. XSS vulnerabilities allow attackers to inject malicious scripts into web pages, potentially compromising user data, hijacking sessions, or performing other malicious actions.

To fix this issue securely, you should avoid using flask.make_response() with untrusted or user-supplied data. Instead, use flask.render_template() for rendering HTML templates, as it automatically escapes user input to prevent XSS attacks. If you're returning data from an API, use flask.jsonify() to serialize data to JSON format.

Code examples

# VULNERABLE CODE - Directly passing user input to make_response() without sanitization
user_input = request.args.get('input')
response = flask.make_response(user_input)
# SECURE CODE - Using render_template() to render HTML templates with automatic escaping
user_input = request.args.get('input')
response = flask.render_template('template.html', user_input=user_input)
# SECURE CODE - Using jsonify() to return data from an API
data = {'key': request.args.get('input')}
response = flask.jsonify(data)

Additional recommendations

  • Follow the principle of least privilege and sanitize all user input before rendering or processing it.
  • Implement input validation and output encoding to prevent injection attacks.
  • Adhere to the OWASP Application Security Verification Standard (ASVS) for secure coding practices.
  • Consider using Content Security Policy (CSP) headers to mitigate XSS risks further.
  • Regularly update Flask and its dependencies to ensure you have the latest security patches.

Rule ID: WS-I013-PYTHON-00095


To ignore this finding as an exception, reply to this conversation with #wiz_ignore reason

If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).


To get more details on how to remediate this issue using AI, reply to this conversation with #wiz remediate

def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
response = make_response(f(*args, **kwargs))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Low SAST Finding

Unsafe Usage of flask.make_response() with Unescaped Content (CWE-79)

More Details

The flask.make_response() function is used to create a response object without properly escaping the content. If the response contains user-supplied data or untrusted content, it can lead to a Cross-Site Scripting (XSS) vulnerability. XSS vulnerabilities allow attackers to inject malicious scripts into web pages, which can lead to data theft, session hijacking, and other security risks.

When rendering HTML content, it is crucial to escape or sanitize any user-supplied data to prevent XSS attacks. Failing to do so can allow attackers to inject malicious scripts that will be executed in the user's browser, potentially compromising their data or session. The consequences of an XSS attack can be severe, including data theft, account takeover, and the spread of malware. To avoid this issue, use flask.render_template() for rendering HTML templates, as it automatically escapes user input. For returning data from an API, use flask.jsonify() instead.

Attribute Value
Impact Medium
Likelihood Low

Remediation

The flask.make_response() function in Flask can lead to cross-site scripting (XSS) vulnerabilities if the response content is not properly sanitized or escaped. XSS vulnerabilities allow attackers to inject malicious scripts into web pages, potentially compromising user data, hijacking sessions, or performing other malicious actions.

To fix this issue securely, you should avoid using flask.make_response() with untrusted or user-supplied data. Instead, use flask.render_template() for rendering HTML templates, as it automatically escapes user input to prevent XSS attacks. If you're returning data from an API, use flask.jsonify() to serialize data to JSON format.

Code examples

# VULNERABLE CODE - Directly passing user input to make_response() without sanitization
user_input = request.args.get('input')
response = flask.make_response(user_input)
# SECURE CODE - Using render_template() to render HTML templates with automatic escaping
user_input = request.args.get('input')
response = flask.render_template('template.html', user_input=user_input)
# SECURE CODE - Using jsonify() to return data from an API
data = {'key': request.args.get('input')}
response = flask.jsonify(data)

Additional recommendations

  • Follow the principle of least privilege and sanitize all user input before rendering or processing it.
  • Implement input validation and output encoding to prevent injection attacks.
  • Adhere to the OWASP Application Security Verification Standard (ASVS) for secure coding practices.
  • Consider using Content Security Policy (CSP) headers to mitigate XSS risks further.
  • Regularly update Flask and its dependencies to ensure you have the latest security patches.

Rule ID: WS-I013-PYTHON-00095


To ignore this finding as an exception, reply to this conversation with #wiz_ignore reason

If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).


To get more details on how to remediate this issue using AI, reply to this conversation with #wiz remediate

def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
response = make_response(f(*args, **kwargs))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Low SAST Finding

Unsafe Usage of flask.make_response() with Unescaped Content (CWE-79)

More Details

The flask.make_response() function is used to create a response object without properly escaping the content. If the response contains user-supplied data or untrusted content, it can lead to a Cross-Site Scripting (XSS) vulnerability. XSS vulnerabilities allow attackers to inject malicious scripts into web pages, which can lead to data theft, session hijacking, and other security risks.

When rendering HTML content, it is crucial to escape or sanitize any user-supplied data to prevent XSS attacks. Failing to do so can allow attackers to inject malicious scripts that will be executed in the user's browser, potentially compromising their data or session. The consequences of an XSS attack can be severe, including data theft, account takeover, and the spread of malware. To avoid this issue, use flask.render_template() for rendering HTML templates, as it automatically escapes user input. For returning data from an API, use flask.jsonify() instead.

Attribute Value
Impact Medium
Likelihood Low

Remediation

The flask.make_response() function in Flask can lead to cross-site scripting (XSS) vulnerabilities if the response content is not properly sanitized or escaped. XSS vulnerabilities allow attackers to inject malicious scripts into web pages, potentially compromising user data, hijacking sessions, or performing other malicious actions.

To fix this issue securely, you should avoid using flask.make_response() with untrusted or user-supplied data. Instead, use flask.render_template() for rendering HTML templates, as it automatically escapes user input to prevent XSS attacks. If you're returning data from an API, use flask.jsonify() to serialize data to JSON format.

Code examples

# VULNERABLE CODE - Directly passing user input to make_response() without sanitization
user_input = request.args.get('input')
response = flask.make_response(user_input)
# SECURE CODE - Using render_template() to render HTML templates with automatic escaping
user_input = request.args.get('input')
response = flask.render_template('template.html', user_input=user_input)
# SECURE CODE - Using jsonify() to return data from an API
data = {'key': request.args.get('input')}
response = flask.jsonify(data)

Additional recommendations

  • Follow the principle of least privilege and sanitize all user input before rendering or processing it.
  • Implement input validation and output encoding to prevent injection attacks.
  • Adhere to the OWASP Application Security Verification Standard (ASVS) for secure coding practices.
  • Consider using Content Security Policy (CSP) headers to mitigate XSS risks further.
  • Regularly update Flask and its dependencies to ensure you have the latest security patches.

Rule ID: WS-I013-PYTHON-00095


To ignore this finding as an exception, reply to this conversation with #wiz_ignore reason

If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).


To get more details on how to remediate this issue using AI, reply to this conversation with #wiz remediate

@ahosgood ahosgood merged commit d094d71 into main May 14, 2026
28 checks passed
@ahosgood ahosgood deleted the feature/flask-cache-headers branch May 14, 2026 14:00
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