fix static scan warnings

This commit is contained in:
Kenneth Kehl
2025-04-01 08:00:33 -07:00
parent e419d843a6
commit 91f3e6a557
9 changed files with 32 additions and 29 deletions

View File

@@ -23,7 +23,7 @@ def accept_invite(token):
<a href={url_for("main.sign_out")} class="usa-link">Sign out</a>
and click the link again to accept this invite.
"""
)
) # nosec
flash(message=message)
@@ -98,7 +98,7 @@ def accept_org_invite(token):
""".format(
current_user.email_address, url_for("main.sign_out")
)
)
) # nosec
flash(message=message)

View File

@@ -351,7 +351,7 @@ def _get_job_counts(job):
Markup(
f"""total<span class="usa-sr-only">
{"text message" if job_type == "sms" else job_type}s</span>"""
),
), # nosec
"",
job.notification_count,
],
@@ -359,7 +359,7 @@ def _get_job_counts(job):
Markup(
f"""pending<span class="usa-sr-only">
{message_count_noun(job.notifications_sending, job_type)}</span>"""
),
), # nosec
"pending",
job.notifications_sending,
],
@@ -367,7 +367,7 @@ def _get_job_counts(job):
Markup(
f"""delivered<span class="usa-sr-only">
{message_count_noun(job.notifications_delivered, job_type)}</span>"""
),
), # nosec
"delivered",
job.notifications_delivered,
],
@@ -375,7 +375,7 @@ def _get_job_counts(job):
Markup(
f"""failed<span class="usa-sr-only">
{message_count_noun(job.notifications_failed, job_type)}</span>"""
),
), # nosec
"failed",
job.notifications_failed,
],
@@ -465,4 +465,4 @@ def get_preview_of_content(notification):
notification["personalisation"],
redact_missing_personalisation=True,
).subject
)
) # nosec

View File

@@ -4,6 +4,7 @@ import uuid
from string import ascii_uppercase
from zipfile import BadZipFile
import bleach
from flask import (
abort,
current_app,
@@ -170,7 +171,9 @@ def send_messages(service_id, template_id):
error_message = '<span class="error-message usa-error-message">'
error_message = f"{error_message}{first_field_errors[0]}"
error_message = f"{error_message}</span>"
error_message = Markup(error_message)
# use 'nosec' because we applied bleach.clean to strip dangerous tags
error_message = bleach.clean(error_message)
error_message = Markup(error_message) # nosec
flash(error_message)
column_headings = get_spreadsheet_column_headings_from_template(template)

View File

@@ -62,7 +62,7 @@ def _get_access_token(code): # pragma: no cover
code_param = f"code={code}"
url = f"{base_url}{cli_assert}&{cli_assert_type}&{code_param}&grant_type=authorization_code"
headers = {"Authorization": "Bearer %s" % token}
response = requests.post(url, headers=headers)
response = requests.post(url, headers=headers, timeout=30)
response_json = response.json()
id_token = get_id_token(response_json)
@@ -88,10 +88,7 @@ def _get_access_token(code): # pragma: no cover
def _get_user_email_and_uuid(access_token): # pragma: no cover
headers = {"Authorization": "Bearer %s" % access_token}
user_info_url = os.getenv("LOGIN_DOT_GOV_USER_INFO_URL")
user_attributes = requests.get(
user_info_url,
headers=headers,
)
user_attributes = requests.get(user_info_url, headers=headers, timeout=30)
user_email = user_attributes.json()["email"]
user_uuid = user_attributes.json()["sub"]
return user_email, user_uuid

View File

@@ -17,7 +17,7 @@ def _sign_out_at_login_dot_gov():
url = f"{base_url}{client_id}&{post_logout_redirect_uri}"
current_app.logger.info(f"url={url}")
response = requests.post(url)
response = requests.post(url, timeout=30)
# response = requests.post(url)
current_app.logger.info(f"login.gov response: {response.text}")

View File

@@ -698,9 +698,7 @@ def _get_content_count_error_and_message_for_template(template):
# Check for blocked characters
if contains_blocked_characters(template.content):
warning = f"{s1}{s2}"
return False, Markup(
warning
) # 🚨 ONLY show the warning, hiding "Will be charged..."
return False, Markup(warning) # nosec
# If message is too long, return the length error
if template.is_message_too_long():
@@ -715,11 +713,11 @@ def _get_content_count_error_and_message_for_template(template):
return False, Markup(
f"Will be charged as {message_count(template.fragment_count, template.template_type)} "
f"(not including personalization)."
)
) # nosec
return False, Markup(
f"Will be charged as {message_count(template.fragment_count, template.template_type)}."
)
) # nosec
@main.route(