Skip to content

Missing cryptography dependency breaks /account/login (regression from #12724) #13055

Description

@RsbhThakur

Problem

A recent commit has accidentally removed cryptography==44.0.2 from requirements.txt. Because the core /account/login process imports and relies on cryptography.fernet.Fernet to encrypt S3 keys into session cookies, any clean build or new installation of the Open Library environment completely fails to log in, raising a ModuleNotFoundError and throwing a 500 Internal Server Error.

Image

During login attempts, the traceback screen shows:

<class 'ModuleNotFoundError'> at /account/login
No module named 'cryptography'

Traceback:
Python  /openlibrary/openlibrary/accounts/model.py in _get_fernet, line 90
        def _get_fernet():
            from cryptography.fernet import Fernet

Root Cause Analysis

  1. Commit e420e4506 ("feat(security): store S3 keys as encrypted session cookie") introduced cookie-based encryption for S3 keys. This feature imported cryptography.fernet.Fernet and pinned cryptography==44.0.2 in requirements.txt.
  2. Commit 3ee6fa309 ("feat(proxy): route outbound requests through single authenticated http_proxy (feat(proxy): route outbound requests through single authenticated http_proxy #12724)") updated outbound requests proxy settings. During this commit, cryptography==44.0.2 was accidentally omitted/deleted from requirements.txt (likely due to an outdated local environment or merge conflict misresolution), while the application code (openlibrary/accounts/model.py) still expects it.

Proposed Fix

Add cryptography==44.0.2 back to requirements.txt under beautifulsoup4:

diff --git a/requirements.txt b/requirements.txt
index e1631b8fc..6e22e9408 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,6 +3,7  @@ amightygirl.paapi5-python-sdk==1.0.0
 APScheduler==3.11.2
 Babel==2.18.0
 beautifulsoup4==4.14.3
+cryptography==44.0.2
 eventer==0.1.1
 fastapi==0.136.3
 feedparser==6.0.12

Reproducing the bug

Method 1

  1. Uninstall the package from your running container:
    docker compose exec -u root web python3 -m pip uninstall -y cryptography
    docker compose exec -u root fast_web python3 -m pip uninstall -y cryptography
  2. Restart the web services to force Python to reload packages from disk:
    docker compose restart web fast_web
  3. Go to http://localhost:8080/account/login and try to log in.
    • Expected behavior: Login succeeds and redirects you.
    • Actual behavior: Server responds with a 500 Internal Server Error due to ModuleNotFoundError: No module named 'cryptography'.

Method 2:

In any fresh setup (like CI/CD pipelines, staging/production builds, or clean checkouts):

  1. Build the base image from scratch (ensuring local virtual environments like .venv are deleted or ignored so they don't break the build context on Windows):
    docker build -f docker/Dockerfile.olbase -t openlibrary/olbase:latest .
  2. Build the development containers on top of your new base image:
    docker compose build --no-cache && docker compose up -d
  3. Go to http://localhost:8080/account/login and attempt to log in.
    • Expected behavior: Login succeeds and redirects you.
    • Actual behavior: Login crashes with ModuleNotFoundError: No module named 'cryptography'.

Context

  • Browser (Chrome, Safari, Firefox, etc):
  • OS (Windows, Mac, etc):
  • Logged in (Y/N):
  • Environment (prod, dev, local): prod

Breakdown

Implementation Details (for maintainers)

Requirements Checklist

  • [ ]

Related files

Stakeholders


Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: ResponseIssues which require feedback from leadPriority: 1Do this week, receiving emails, time sensitive, . [managed]Type: BugSomething isn't working. [managed]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions