Skip to main content

Selenium Teleport 2.1.1: Safer Browser-State Restoration

Encryption, origin checks, expired-cookie handling, and the limits that matter when reusing authenticated Selenium state.

3 min read
Selenium Teleport 2.1.1: Safer Browser-State Restoration
On this page

Release checked September 5, 2026
This article now reflects v2.1.1 and the documented behavior of that project. Existing URLs are preserved so older links continue to work.

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

StateSupport
CookiesCookies visible to Selenium on the current page
localStorage and sessionStorageCurrent-origin values
IndexedDBDatabase names, versions, and store names as metadata only
IndexedDB recordsNot exported or restored
Other visited originsNot captured as a complete browser profile

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.

bash
python -m pip install "selenium-teleport[security]==2.1.1"
python
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.

Current project documentation

Dhiraj Das

About the Author

Dhiraj Das is an Automation Consultant with over a decade of experience building systems that expose failures, reduce flakiness, and make complex workflows repeatable. He applies that discipline to AI-agent validation, LLM testing, and postmortems.

He shares small open source utilities from real automation work, including: waitless (flaky tests), sb-stealth-wrapper (bot detection), selenium-teleport (state persistence), selenium-chatbot-test (AI chatbot testing), lumos-shadowdom (Shadow DOM), and visual-guard (visual regression).

Share this article: