Skip to content

Commit 9b576cf

Browse files
move out of stock over to wow routes (#33)
* move out of stock over to wow routes * add semgrep config * Ensure 'NO_RATE_LIMIT' is correctly cast to boolean Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update .semgrep.yml * Update and rename .semgrep.yml to semgrep.config.yaml --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 8a6da85 commit 9b576cf

File tree

3 files changed

+101
-55
lines changed

3 files changed

+101
-55
lines changed

app.py

-55
Original file line numberDiff line numberDiff line change
@@ -758,61 +758,6 @@ def bestdeals():
758758
)
759759

760760

761-
@app.route("/wowoutofstock", methods=["GET", "POST"])
762-
def wow_outofstock_api():
763-
if request.method == "GET":
764-
return return_safe_html(render_template("wow_outofstock.html"))
765-
elif request.method == "POST":
766-
category = int(request.form.get("item_class"))
767-
if category == -1:
768-
include_cat = []
769-
else:
770-
include_cat = [category]
771-
json_data = {
772-
"region": request.form.get("region"),
773-
"salesPerDay": float(request.form.get("salesPerDay")),
774-
"avgPrice": int(request.form.get("avgPrice")),
775-
"minMarketValue": int(request.form.get("minMarketValue")),
776-
"populationWP": int(request.form.get("populationWP")),
777-
"populationBlizz": int(request.form.get("populationBlizz")),
778-
"rankingWP": int(request.form.get("rankingWP")),
779-
"includeCategories": include_cat,
780-
"excludeCategories": [],
781-
}
782-
783-
response = requests.post(
784-
f"{api_url}/wow/outofstock",
785-
headers={"Accept": "application/json"},
786-
json=json_data,
787-
).json()
788-
789-
if "data" not in response or len(response["data"]) == 0:
790-
logger.error(
791-
f"Error no matching data with given inputs {json_data} response {response}"
792-
)
793-
if NO_RATE_LIMIT:
794-
return f"Error no matching data with given inputs {json_data} response {response}"
795-
# send generic error message to remove XSS potential
796-
return "error no matching results found matching search inputs"
797-
response = response["data"]
798-
799-
for row in response:
800-
del row["itemID"]
801-
del row["item_class"]
802-
del row["item_subclass"]
803-
del row["connectedRealmId"]
804-
del row["itemQuality"]
805-
806-
fieldnames = list(response[0].keys())
807-
808-
return return_safe_html(
809-
render_template(
810-
"wow_outofstock.html",
811-
results=response,
812-
fieldnames=fieldnames,
813-
len=len,
814-
)
815-
)
816761

817762

818763
@app.route("/petimport", methods=["GET", "POST"])

routes/wow.py

+59
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
wow_bp = Blueprint("wow", __name__)
99

10+
NO_RATE_LIMIT = os.getenv("NO_RATE_LIMIT", "False").lower() in ("true", "1", "yes")
1011

1112
@wow_bp.route("/wow", methods=["GET", "POST"])
1213
def wow():
@@ -32,3 +33,61 @@ def itemnames():
3233
"itemnames.html", results=resp_list, fieldnames=["id", "name"], len=len
3334
)
3435
)
36+
37+
38+
@wow_bp.route("/wowoutofstock", methods=["GET", "POST"])
39+
def wow_outofstock_api():
40+
if request.method == "GET":
41+
return return_safe_html(render_template("wow_outofstock.html"))
42+
elif request.method == "POST":
43+
category = int(request.form.get("item_class"))
44+
if category == -1:
45+
include_cat = []
46+
else:
47+
include_cat = [category]
48+
json_data = {
49+
"region": request.form.get("region"),
50+
"salesPerDay": float(request.form.get("salesPerDay")),
51+
"avgPrice": int(request.form.get("avgPrice")),
52+
"minMarketValue": int(request.form.get("minMarketValue")),
53+
"populationWP": int(request.form.get("populationWP")),
54+
"populationBlizz": int(request.form.get("populationBlizz")),
55+
"rankingWP": int(request.form.get("rankingWP")),
56+
"includeCategories": include_cat,
57+
"excludeCategories": [],
58+
}
59+
60+
response = requests.post(
61+
f"{api_url}/wow/outofstock",
62+
headers={"Accept": "application/json"},
63+
json=json_data,
64+
).json()
65+
66+
if "data" not in response or len(response["data"]) == 0:
67+
# @coderabbitai will need to move the logger function over so it can be used here
68+
print(
69+
f"Error no matching data with given inputs {json_data} response {response}"
70+
)
71+
if NO_RATE_LIMIT:
72+
return f"Error no matching data with given inputs {json_data} response {response}"
73+
# send generic error message to remove XSS potential
74+
return "error no matching results found matching search inputs"
75+
response = response["data"]
76+
77+
for row in response:
78+
del row["itemID"]
79+
del row["item_class"]
80+
del row["item_subclass"]
81+
del row["connectedRealmId"]
82+
del row["itemQuality"]
83+
84+
fieldnames = list(response[0].keys())
85+
86+
return return_safe_html(
87+
render_template(
88+
"wow_outofstock.html",
89+
results=response,
90+
fieldnames=fieldnames,
91+
len=len,
92+
)
93+
)

semgrep.config.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
rules:
2+
- id: nan-injection
3+
message: Found user input going directly into typecast for bool(), float(), or complex(). This allows an
4+
attacker to inject Python's not-a-number (NaN) into the typecast. This results in undefind behavior,
5+
particularly when doing comparisons. Either cast to a different type, or add a guard checking for
6+
all capitalizations of the string 'nan'.
7+
languages:
8+
- python
9+
severity: ERROR
10+
mode: taint
11+
pattern-sources:
12+
- pattern-either:
13+
- pattern: flask.request.$SOMETHING.get(...)
14+
- pattern: flask.request.$SOMETHING[...]
15+
- patterns:
16+
- pattern-inside: |
17+
@$APP.route(...)
18+
def $FUNC(..., $ROUTEVAR, ...):
19+
...
20+
- pattern: $ROUTEVAR
21+
pattern-sinks:
22+
- pattern-either:
23+
- pattern: float(...)
24+
- pattern: bool(...)
25+
- pattern: complex(...)
26+
pattern-sanitizers:
27+
- not_conflicting: true
28+
pattern: $ANYTHING(...)
29+
metadata:
30+
references:
31+
- https://discuss.python.org/t/nan-breaks-min-max-and-sorting-functions-a-solution/2868
32+
- https://blog.bitdiscovery.com/2021/12/python-nan-injection/
33+
category: security
34+
cwe:
35+
- 'CWE-704: Incorrect Type Conversion or Cast'
36+
technology:
37+
- flask
38+
subcategory:
39+
- vuln
40+
impact: MEDIUM
41+
likelihood: MEDIUM
42+
confidence: MEDIUM

0 commit comments

Comments
 (0)