-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a rule to detect usage of uuid version 1 in python (#3517)
* added a rule to detect usage of uuid version 1 in python * Applying suggestion to move url from message to references Co-authored-by: Pieter De Cremer (Semgrep) <pieter@r2c.dev> --------- Co-authored-by: Pieter De Cremer (Semgrep) <pieter@r2c.dev>
- Loading branch information
1 parent
3b05904
commit e8a1345
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import uuid | ||
def example_1(): | ||
# ruleid:insecure-uuid-version | ||
uuid = uuid.uuid1() | ||
|
||
from uuid import uuid1 | ||
def example_2(): | ||
# ruleid:insecure-uuid-version | ||
uuid = uuid1() | ||
|
||
from uuid import * | ||
def example_3(): | ||
# ruleid:insecure-uuid-version | ||
uuid = uuid1() | ||
|
||
import uuid | ||
def unrelated_function(): | ||
# ok:insecure-uuid-version | ||
uuid = uuid4() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
rules: | ||
- id: insecure-uuid-version | ||
patterns: | ||
- pattern: uuid.uuid1(...) | ||
message: | | ||
Using UUID version 1 for UUID generation can lead to predictable UUIDs based on system information (e.g., MAC address, timestamp). This may lead to security risks such as the sandwich attack. Consider using `uuid.uuid4()` instead for better randomness and security. | ||
metadata: | ||
references: | ||
- https://www.landh.tech/blog/20230811-sandwich-attack/ | ||
cwe: | ||
- 'CWE-330: Use of Insufficiently Random Values' | ||
owasp: | ||
- A02:2021 - Cryptographic Failures | ||
asvs: | ||
section: V6 Stored Cryptography Verification Requirements | ||
control_id: 6.3.2 Insecure UUID Generation | ||
control_url: https://github.com/OWASP/ASVS/blob/master/4.0/en/0x14-V6-Cryptography.md#v63-random-values | ||
version: '4' | ||
category: security | ||
technology: | ||
- python | ||
subcategory: | ||
- audit | ||
likelihood: LOW | ||
impact: MEDIUM | ||
confidence: MEDIUM | ||
languages: | ||
- python | ||
severity: WARNING | ||
fix-regex: | ||
regex: uuid1 | ||
replacement: uuid4 | ||
|