CLincat / vulcat

vulcat可用于扫描Web端常见的CVE、CNVD等编号的漏洞,发现漏洞时会返回Payload信息。部分漏洞还支持命令行交互模式,可以持续利用漏洞
GNU General Public License v3.0
124 stars 17 forks source link

Use of Deprecated `utcnow()` or `utcfromtimestamp()` APIs #6

Open ShreyTiwari opened 3 weeks ago

ShreyTiwari commented 3 weeks ago

Hi there! 👋

I noticed that the codebase uses datetime.utcnow() or datetime.utcfromtimestamp(). These are deprecated and won't work with Python 3.12. They also handle naïve datetimes, which can lead to bugs. Could we switch to timezone-aware alternatives?

CodeQL Alerts

Here are the specific instances CodeQL flagged:

  1. https://github.com/CLincat/vulcat/blob/5730e363ff6873bb0893b25cf7119a85c06b37a4/thirdparty/flask_unsign/helpers.py#L44
  2. https://github.com/CLincat/vulcat/blob/5730e363ff6873bb0893b25cf7119a85c06b37a4/thirdparty/tqdm/std.py#L468

Explanation

Issue:

Example Problem:

from datetime import datetime
ts = 1571595618.0
x = datetime.utcfromtimestamp(ts)
x_ts = x.timestamp()
assert ts == x_ts, f"{ts} != {x_ts}" # Can fail in non-UTC locales

Recommended Solution: Switch to time zone-aware methods:

from datetime import datetime, timezone
# Replace utcnow()
dt_now = datetime.now(tz=timezone.utc)
# Replace utcfromtimestamp()
ts = 1571595618.0
x = datetime.fromtimestamp(ts, tz=timezone.utc)
x_ts = x.timestamp()
assert ts == x_ts, f"{ts} != {x_ts}" # This succeeds

Action Required:

References:

For more details, see:

Thank you so much for your time and effort in maintaining this project! 🌟

Best, Shrey