Skip to content

Commit 4ab3fff

Browse files
committed
Python: Fix untrusted data to external API example
The hmac.digest function was only added in python 3.7, so obviously doesn't work on Python 2
1 parent cbfcfdf commit 4ab3fff

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| hmac.digest [param 1] | 1 | 1 |
1+
| hmac.new [param 1] | 1 | 1 |
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
edges
2-
| test.py:13:16:13:27 | ControlFlowNode for Attribute | test.py:15:38:15:41 | ControlFlowNode for data |
2+
| test.py:13:16:13:27 | ControlFlowNode for Attribute | test.py:15:36:15:39 | ControlFlowNode for data |
33
nodes
44
| test.py:13:16:13:27 | ControlFlowNode for Attribute | semmle.label | ControlFlowNode for Attribute |
5-
| test.py:15:38:15:41 | ControlFlowNode for data | semmle.label | ControlFlowNode for data |
5+
| test.py:15:36:15:39 | ControlFlowNode for data | semmle.label | ControlFlowNode for data |
66
#select
7-
| test.py:15:38:15:41 | ControlFlowNode for data | test.py:13:16:13:27 | ControlFlowNode for Attribute | test.py:15:38:15:41 | ControlFlowNode for data | Call to hmac.digest [param 1] with untrusted data from $@. | test.py:13:16:13:27 | ControlFlowNode for Attribute | ControlFlowNode for Attribute |
7+
| test.py:15:36:15:39 | ControlFlowNode for data | test.py:13:16:13:27 | ControlFlowNode for Attribute | test.py:15:36:15:39 | ControlFlowNode for data | Call to hmac.new [param 1] with untrusted data from $@. | test.py:13:16:13:27 | ControlFlowNode for Attribute | ControlFlowNode for Attribute |

python/ql/test/query-tests/Security/CWE-020-ExternalAPIs/test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
def hmac_example():
1313
data_raw = request.args.get("data").encode('utf-8')
1414
data = base64.decodebytes(data_raw)
15-
digest = hmac.digest(SECRET_KEY, data, hashlib.sha256)
15+
my_hmac = hmac.new(SECRET_KEY, data, hashlib.sha256)
16+
digest = my_hmac.digest()
1617
print(digest)
1718
return "ok"
1819

@@ -32,4 +33,5 @@ def unknown_lib_2():
3233

3334

3435
if __name__ == "__main__":
36+
# http://127.0.0.1:5000/hmac-example?data=aGVsbG8gd29ybGQh
3537
app.run(debug=True)

0 commit comments

Comments
 (0)