-
Notifications
You must be signed in to change notification settings - Fork 0
test semgrep for directly-returned-format-string and nan-injection #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,4 +90,57 @@ def wow_outofstock_api(): | |
fieldnames=fieldnames, | ||
len=len, | ||
) | ||
) | ||
|
||
@wow_bp.route("/petshoppinglist", methods=["GET", "POST"]) | ||
def petshoppinglist(): | ||
# return redirect("https://saddlebagexchange.com/wow/shopping-list") | ||
|
||
# DEPRECIATED | ||
if request.method == "GET": | ||
return return_safe_html(render_template("petshoppinglist.html")) | ||
elif request.method == "POST": | ||
json_data = { | ||
"region": request.form.get("region"), | ||
"itemID": int(request.form.get("petID")), | ||
"maxPurchasePrice": int(request.form.get("maxPurchasePrice")), | ||
"connectedRealmIDs": {}, | ||
} | ||
|
||
print(json_data) | ||
|
||
response = requests.post( | ||
f"{api_url}/wow/shoppinglistx", | ||
headers={"Accept": "application/json"}, | ||
json=json_data, | ||
).json() | ||
|
||
print(response) | ||
|
||
if "data" not in response: | ||
print( | ||
f"Error no matching data with given inputs {json_data} response {response}" | ||
) | ||
if NO_RATE_LIMIT: | ||
return f"Error no matching data with given inputs {json_data} response {response}" | ||
# send generic error message to remove XSS potential | ||
return f"error no matching results found matching search inputs" | ||
|
||
Comment on lines
+120
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error handling to prevent XSS vulnerabilities and ensure consistent error responses Returning formatted strings that include user input directly can lead to cross-site scripting (XSS) vulnerabilities if the input is not properly sanitized. In this block, error messages include Consider standardizing the error responses using safe rendering methods and avoiding inclusion of user-provided data. Apply this diff to fix the issue: if NO_RATE_LIMIT:
- return f"Error no matching data with given inputs {json_data} response {response}"
+ return return_safe_html("Error: no matching data found for the provided inputs.")
# send generic error message to remove XSS potential
- return f"error no matching results found matching search inputs"
+ return return_safe_html("Error: no matching results found matching search inputs.") Also, remove the unnecessary
🧰 Tools🪛 Ruff
🪛 semgrep
|
||
response = response["data"] | ||
|
||
column_order = [ | ||
"realmID", | ||
"price", | ||
"quantity", | ||
"realmName", | ||
"realmNames", | ||
"link", | ||
] | ||
response = [{key: item.get(key) for key in column_order} for item in response] | ||
fieldnames = list(response[0].keys()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential empty response when accessing At line 140, Consider checking if if response:
fieldnames = list(response[0].keys())
else:
return return_safe_html("No data available for the given inputs.") |
||
|
||
return return_safe_html( | ||
render_template( | ||
"petshoppinglist.html", results=response, fieldnames=fieldnames, len=len | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential exceptions when converting form data to integers
Using
int()
directly on form data may raise aValueError
if the input is not a valid integer. It's recommended to validate the input and handle possible exceptions to avoid server errors.Consider adding try-except blocks or input validation. For example: