A saved browser session is authentication material. Selenium Teleport 2.1.1 hardens the restore boundary and documents it more precisely: it restores supported state from the current origin, checks the destination, and can encrypt saved files. It does not make a session portable under every authentication scheme.
Know exactly what is saved
Encryption must be enabled explicitly
Install the security extra, provide an existing Fernet key outside source control, and pass encrypt=True. Setting TELEPORT_ENCRYPTION_KEY supplies the key; it does not enable encrypted saves by itself. Keep state files and browser profiles out of the repository.
python -m pip install "selenium-teleport[security]==2.1.1"from selenium_teleport import Teleport, create_driver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Supply TELEPORT_ENCRYPTION_KEY securely before running.
driver = create_driver()
try:
with Teleport(driver, 'session.enc', encrypt=True, auto_save=False) as session:
if session.has_state():
session.load('https://test.example.com/dashboard')
else:
driver.get('https://test.example.com/login')
# Complete your application's approved login flow here.
WebDriverWait(driver, 30).until(
EC.visibility_of_element_located((By.ID, 'account-menu'))
)
session.save() # Explicit save lets failures reach the caller.
finally:
driver.quit()The example assumes a controlled application with an account-menu element that proves the expected identity is authenticated. Implement the initial login before using it. Revalidate restored state rather than assuming that navigation means authentication succeeded.
Origin and expiry checks
Storage-bearing state must match the destination origin, including scheme, host, and effective port. Cookie-only state has a narrower supported cross-subdomain rule. Expired cookies are removed by default, and an entirely expired cookie set raises ExpiredSessionError.
Validation is not a sandbox
Destination checks reject non-HTTP(S) URLs and literal non-public IP addresses, and can apply configured domain lists. They do not resolve hostnames before navigation, so they are not complete SSRF protection. Path sanitization rejects traversal syntax but does not confine all filesystem access on its own.
Deletion is best effort
delete_state(..., secure=True) attempts an overwrite before removing the file. Snapshots, journaling, backups, and storage hardware may retain copies. It is not a forensic-erasure or regulatory-compliance guarantee. Revoke a session if its state file may have been exposed.
Keep login coverage separate
State reuse speeds tests whose purpose is elsewhere. Retain dedicated tests for login, session expiry, logout, and revoked credentials. The companion article explains where that split helps.

