From d6247fdd975e7d0c61bec98cf1ea4f7f3dd09ea1 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 16 Nov 2026 11:35:21 -0500 Subject: [PATCH 1/4] Replace PyOTP with an in-house 2FA handler --- seleniumbase/fixtures/shared_utils.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/seleniumbase/fixtures/shared_utils.py b/seleniumbase/fixtures/shared_utils.py index 7a5b9cb6f51..e07321d1529 100644 --- a/seleniumbase/fixtures/shared_utils.py +++ b/seleniumbase/fixtures/shared_utils.py @@ -56,9 +56,12 @@ def get_mfa_code(totp_key=None): to using the one provided in [seleniumbase/config/settings.py]. Google Authenticator codes expire & change at 30-sec intervals. If the fetched password expires in the next 1.2 seconds, waits - for a new one before returning it (may take up to 1.2 seconds). - See https://pyotp.readthedocs.io/en/latest/ for details.""" - import pyotp + for a new one before returning it (may take up to 1.2 seconds).""" + import base64 + import binascii + import hashlib + import hmac + import struct if not totp_key: totp_key = settings.TOTP_KEY @@ -73,8 +76,20 @@ def get_mfa_code(totp_key=None): if not float(cycle_lifespan) > 0.96: # The new password cycle has begun break - totp = pyotp.TOTP(totp_key) - return str(totp.now()) + normalized_key = "".join(str(totp_key).split()).upper() + padded_key = normalized_key + "=" * (-len(normalized_key) % 8) + try: + secret_bytes = base64.b32decode(padded_key) + except binascii.Error as exc: + raise ValueError( + "Invalid TOTP secret key: must be a valid Base32 string." + ) from exc + counter = struct.pack(">Q", int(time.time() // 30)) + digest = hmac.new(secret_bytes, counter, hashlib.sha1).digest() + offset = digest[-1] & 0x0F + truncated = struct.unpack(">I", digest[offset: offset + 4])[0] + code_int = (truncated & 0x7FFFFFFF) % 1000000 + return f"{code_int:06d}" def is_arm_linux(): From d02d8361d2da328e12b874f2dc7d1cd5635157c4 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 16 Nov 2026 11:42:47 -0500 Subject: [PATCH 2/4] Remove references to PyOTP --- examples/custom_settings.py | 1 - help_docs/features_list.md | 2 +- seleniumbase/config/settings.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/custom_settings.py b/examples/custom_settings.py index 98e395b10ca..92259e3915d 100644 --- a/examples/custom_settings.py +++ b/examples/custom_settings.py @@ -90,7 +90,6 @@ # Google Authenticator # (For 2-factor authentication using a time-based one-time password algorithm) -# (See https://github.com/pyotp/pyotp and https://pypi.org/project/pyotp/ ) # (Also works with Authy and other compatible apps.) # Usage: "self.get_google_auth_password()" (output based on timestamp) # Usage with override: "self.get_google_auth_password(totp_key=TOTP_KEY)" diff --git a/help_docs/features_list.md b/help_docs/features_list.md index 72d2e0611ef..b7c9185de48 100644 --- a/help_docs/features_list.md +++ b/help_docs/features_list.md @@ -34,7 +34,7 @@ * Includes a [website tour builder](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/ReadMe.md) for creating interactive walkthroughs. * Includes a GUI for running pytest scripts: [SeleniumBase Commander](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/commander.md). * Includes integrations for [GitHub Actions](https://seleniumbase.io/integrations/github/workflows/ReadMe/), [Google Cloud](https://github.com/seleniumbase/SeleniumBase/tree/master/integrations/google_cloud/ReadMe.md), [Azure](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/azure/jenkins/ReadMe.md), [S3](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/s3_logging_plugin.py), and [Docker](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/docker/ReadMe.md). -* Can handle Google Authenticator logins with [Python's one-time password library](https://pyotp.readthedocs.io/en/latest/). +* Can handle Google Authenticator logins that require 2FA via time-based tokens. * Can load and make assertions on PDF files from websites or the local file system. * Can inspect HTML to find issues and points of interest with the [HTML Inspector](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/html_inspector.md). * Is backwards-compatible with Python [WebDriver](https://www.selenium.dev/projects/) methods. (Use: `self.driver`) diff --git a/seleniumbase/config/settings.py b/seleniumbase/config/settings.py index 745381d6795..d1c9bed7445 100644 --- a/seleniumbase/config/settings.py +++ b/seleniumbase/config/settings.py @@ -158,7 +158,6 @@ # Google Authenticator # (For 2-factor authentication using a time-based one-time password algorithm) -# (See https://github.com/pyotp/pyotp and https://pypi.org/project/pyotp/ ) # (Also works with Authy and other compatible apps.) # Usage: "self.get_google_auth_password()" (output based on timestamp) # Usage with override: "self.get_google_auth_password(totp_key=TOTP_KEY)" From e59b2ac51b1e03ca481d45e97e0f796c82aef396 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 16 Nov 2026 11:43:14 -0500 Subject: [PATCH 3/4] Refresh Python dependencies (remove PyOTP) --- requirements.txt | 1 - setup.py | 1 - 2 files changed, 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7b9747a2290..2c97a000acc 100755 --- a/requirements.txt +++ b/requirements.txt @@ -58,7 +58,6 @@ behave==1.2.6 soupsieve~=2.10.0;python_version<"3.11.5" soupsieve~=4.1.1;python_version>="3.11.5" beautifulsoup4~=4.15.0 -pyotp~=2.11.2 python-xlib==0.33;platform_system=="Linux" PyAutoGUI>=0.9.54;platform_system=="Linux" markdown-it-py==4.3.0 diff --git a/setup.py b/setup.py index b13b2f1775a..cd5325280ce 100755 --- a/setup.py +++ b/setup.py @@ -224,7 +224,6 @@ 'soupsieve~=2.10.0;python_version<"3.11.5"', 'soupsieve~=4.1.1;python_version>="3.11.5"', 'beautifulsoup4~=4.15.0', - 'pyotp~=2.11.2', 'python-xlib==0.33;platform_system=="Linux"', 'PyAutoGUI>=0.9.54;platform_system=="Linux"', 'markdown-it-py==4.3.0', From b2ff1ae63ef427e251248bad8c29193e56b2441e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 16 Nov 2026 11:44:02 -0500 Subject: [PATCH 4/4] Version 4.58.1 --- seleniumbase/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index 0bef3f3f49a..e577199ea67 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "4.58.0" +__version__ = "4.58.1"