Skip to content

Commit c04c52c

Browse files
authored
chore: remove dead auth helper and fix stale default-password docs (#1026)
check_api_password() (an unused HTTPBearer-based dependency, superseded by PasswordAuthMiddleware) and its now-unused imports are dead code - nothing calls it. Removed. Docs across api/CLAUDE.md, docs/3-USER-GUIDE/api-configuration.md, docs/5-CONFIGURATION/security.md, docs/7-DEVELOPMENT/security.md, and docs/SECURITY_REVIEW.md still described a hardcoded default password ("open-notebook-change-me") that PasswordAuthMiddleware doesn't actually have - if OPEN_NOTEBOOK_PASSWORD is unset, auth is fully disabled instead. Updated to match actual behavior.
1 parent fc3f35a commit c04c52c

5 files changed

Lines changed: 7 additions & 49 deletions

File tree

api/auth.py

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import secrets
22
from typing import Optional
33

4-
from fastapi import Depends, HTTPException, Request
5-
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
6-
from loguru import logger
4+
from fastapi import Request
75
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
86
from starlette.responses import JSONResponse, Response
97
from starlette.types import ASGIApp
@@ -14,7 +12,8 @@
1412
class PasswordAuthMiddleware(BaseHTTPMiddleware):
1513
"""
1614
Middleware to check password authentication for all API requests.
17-
Always active with default password if OPEN_NOTEBOOK_PASSWORD is not set.
15+
Auth is fully disabled (no hardcoded default password) if
16+
OPEN_NOTEBOOK_PASSWORD is not set.
1817
Supports Docker secrets via OPEN_NOTEBOOK_PASSWORD_FILE.
1918
"""
2019

@@ -81,44 +80,3 @@ async def dispatch(
8180
# Password is correct, proceed with the request
8281
response = await call_next(request)
8382
return response
84-
85-
86-
# Optional: HTTPBearer security scheme for OpenAPI documentation
87-
security = HTTPBearer(auto_error=False)
88-
89-
90-
def check_api_password(
91-
credentials: Optional[HTTPAuthorizationCredentials] = Depends(security),
92-
) -> bool:
93-
"""
94-
Utility function to check API password.
95-
Can be used as a dependency in individual routes if needed.
96-
Supports Docker secrets via OPEN_NOTEBOOK_PASSWORD_FILE.
97-
Returns True without checking credentials if OPEN_NOTEBOOK_PASSWORD is not configured.
98-
Raises 401 if credentials are missing or don't match the configured password.
99-
"""
100-
password = get_secret_from_env("OPEN_NOTEBOOK_PASSWORD")
101-
102-
# No password configured - skip authentication
103-
if not password:
104-
return True
105-
106-
# No credentials provided
107-
if not credentials:
108-
raise HTTPException(
109-
status_code=401,
110-
detail="Missing authorization",
111-
headers={"WWW-Authenticate": "Bearer"},
112-
)
113-
114-
# Check password (constant-time to avoid a timing side-channel)
115-
if not secrets.compare_digest(
116-
credentials.credentials.encode("utf-8"), password.encode("utf-8")
117-
):
118-
raise HTTPException(
119-
status_code=401,
120-
detail="Invalid password",
121-
headers={"WWW-Authenticate": "Bearer"},
122-
)
123-
124-
return True

docs/3-USER-GUIDE/api-configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ API keys stored in the database are encrypted using Fernet (AES-128-CBC + HMAC-S
302302

303303
| Setting | Default Value | Production Recommendation |
304304
|---------|---------------|---------------------------|
305-
| Password | `open-notebook-change-me` | Set `OPEN_NOTEBOOK_PASSWORD` |
305+
| Password | None - auth is fully disabled until set | Set `OPEN_NOTEBOOK_PASSWORD` |
306306
| Encryption Key | None (must be set) | Set `OPEN_NOTEBOOK_ENCRYPTION_KEY` to any secret string |
307307

308308
**For production deployments, always set custom credentials.**

docs/5-CONFIGURATION/security.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Any string works — it will be securely derived via SHA-256 internally. Use a s
3030

3131
| Setting | Default | Security Level |
3232
|---------|---------|----------------|
33-
| Password | `open-notebook-change-me` | Development only |
33+
| Password | None - auth is fully disabled until `OPEN_NOTEBOOK_PASSWORD` is set | Development only |
3434
| Encryption Key | **None** (must be configured) | Required for API key storage |
3535

3636
**The encryption key has no default.** You must set `OPEN_NOTEBOOK_ENCRYPTION_KEY` before using the API key configuration feature. Without it, encrypting/decrypting API keys will fail.

docs/7-DEVELOPMENT/security.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Never pass user-provided file paths directly to file reading or content extracti
144144

145145
Open Notebook currently uses simple password-based middleware (`PasswordAuthMiddleware`). This is suitable for single-user self-hosted deployments but should be hardened for production:
146146

147-
- Change the default password (`OPEN_NOTEBOOK_PASSWORD`)
147+
- Set `OPEN_NOTEBOOK_PASSWORD` explicitly - there is no hardcoded default password; if it's unset, auth is fully disabled (all requests pass through unchecked)
148148
- Change the default encryption key (`OPEN_NOTEBOOK_ENCRYPTION_KEY`)
149149
- Consider deploying behind a reverse proxy with proper authentication (OAuth, OIDC)
150150

docs/SECURITY_REVIEW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Security review of the API key management implementation for Open Notebook. The
5252
| Item | Status | Notes |
5353
|------|--------|-------|
5454
| Password protection | PASS | Bearer token authentication |
55-
| Default password | PASS | "open-notebook-change-me" when not set |
55+
| Default password | PASS | Auth is fully disabled (not a hardcoded default password) when `OPEN_NOTEBOOK_PASSWORD` is unset |
5656
| Docker secrets support | PASS | `_FILE` suffix for password |
5757
| Security warnings | PASS | Logged when using defaults |
5858

0 commit comments

Comments
 (0)