
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Parse and format HTTP dates, such as Last-Modified and If-Modified-Since headers.
httpdate is a Python library for parsing and formatting HTTP date fields that are
used in headers like Last-Modified
and If-Modified-Since
. It does so in strict
accordance with RFC 9110 Section 5.6.7.
It has only one dependency, which is my tiny leapseconds library that just provides a tuple of official leap seconds.
All HTTP dates (eg, in Last-Modified
headers) must be sent in this format:
# IMF-fixdate
Sun, 06 Nov 1994 08:49:37 GMT
However, RFC 9110 states that recipients must also accept two other obsolete formats:
# rfc850-date
Sunday, 06-Nov-94 08:49:37 GMT
# asctime-date
Sun Nov 6 08:49:37 1994
RFC 9110 criteria for the HTTP date field includes the following:
23:59:60
).1900
or above.It isn't stated explicitly in the RFCs, but httpdate
will only consider a leap second
semantically correct if it's an official leap second.
pip install httpdate
from httpdate import is_valid_httpdate, httpdate_to_unixtime, unixtime_to_httpdate
# Check if an HTTP date (eg, `Last-Modified` header) is valid:
is_valid_httpdate("Sun, 06 Nov 1994 08:49:37 GMT")
try:
# Parse an HTTP date:
httpdate_to_unixtime("Sun, 06 Nov 1994 08:49:37 GMT")
# Parse an HTTP date (rfc850-date):
httpdate_to_unixtime("Sunday, 06-Nov-94 08:49:37 GMT")
# Parse an HTTP date (asctime-date):
httpdate_to_unixtime("Sun Nov 6 08:49:37 1994")
except ValueError:
# Not a valid HTTP date string.
pass
# Format a Unix timestamp as an HTTP date:
try:
unixtime_to_httpdate(784111777)
except ValueError:
# Outside the range supported by the operating system.
pass
is_valid_httpdate(httpdate)
:
httpdate (str)
: An HTTP date string.bool
: True if httpdate
is a valid HTTP date string, otherwise False.TypeError
if httpdate
is not of type str
.httpdate_to_unixtime(httpdate)
:
httpdate (str)
: An HTTP date string.int
: A Unix timestamp (int
).TypeError
if httpdate
is not of type str
.ValueError
if httpdate
is not a valid HTTP date string.unixtime_to_httpdate(unixtime)
:
unixtime (int)
: A Unix timestamp.str
: An HTTP date string.TypeError
if unixtime
is not of type int
.ValueError
if unixtime
represents a year before 1900, or if it is outside
the range supported by the operating system.Unix timestamps are unambiguous, efficient, and can easily be converted to other date-time formats using only the standard library.
When a Last-Modified
header is semantically correct, this conversion — from string to
Unix timestamp and back to string — is lossless. (The only exception is leap seconds;
for example Sat, 31 Dec 2016 23:59:60 GMT
would be returned as Sun, 01 Jan 2017 00:00:00 GMT
. Recipients should interpret these as being identical anyway.)
If you want to store the original string instead, just use is_valid_httpdate()
to
validate before storing.
httpdate
is distributed under the terms of the MIT license.
FAQs
Parse and format HTTP dates, such as Last-Modified and If-Modified-Since headers.
We found that httpdate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.