What changed, and why it matters
This commit fixes a privacy leak in several LNbits wallet API responses. Previously, responses to wallet creation, update, and on-chain wallet operations included a 'user' field that could expose internal user identifiers to anyone with a valid wallet key. The patch now strips that field from responses, and tests confirm it is no longer returned.
Review other wallet-related endpoints to ensure 'user' and similar internal identifiers are consistently excluded from responses, especially where read-only or invoice keys are sufficient for access.
Security signals we found
Information disclosure via API response field
Response-model exclusion of sensitive identifier
Test assertions added to prevent regression
Evidence from the diff
The commit adds ‘user’ to the response_model_exclude set in four API endpoints: create_hot_wallet and confirm_backup in onchain_api.py; api_update_wallet, api_wallets_retrieve, and api_wallet_create_or_update in wallet_api.py. Tests are updated to assert ‘user’ is absent from JSON responses. The change prevents the wallet/user association identifier from being leaked to API callers holding only invoice or admin keys.
Changed components
lnbits/core/views/onchain_api.pylnbits/core/views/wallet_api.pytests/api/test_onchain_wallet.pytests/api/test_wallet_api.pyInspect captured patch +15 / −11
### lnbits/core/views/onchain_api.py
@@ -229,7 +229,7 @@ async def hot_wallet_status(
@onchain_router.post(
"/hot-wallet",
response_model=OnchainWallet,
- response_model_exclude={"adminkey", "inkey"},
+ response_model_exclude={"adminkey", "inkey", "user"},
)
async def create_hot_wallet(
data: NewHotWallet,
@@ -312,7 +312,7 @@ async def backup_hot_wallet(
@onchain_router.post(
"/hot-wallet/{wallet_id}/backup/confirm",
response_model=OnchainWallet,
- response_model_exclude={"adminkey", "inkey"},
+ response_model_exclude={"adminkey", "inkey", "user"},
)
async def confirm_backup(
wallet_id: str,
### lnbits/core/views/wallet_api.py
@@ -185,7 +185,7 @@ async def api_put_stored_paylinks(
return wallet.stored_paylinks.links
-@wallet_router.patch("")
+@wallet_router.patch("", response_model_exclude={"user"})
async def api_update_wallet(
name: str | None = Body(None),
icon: str | None = Body(None),
@@ -276,7 +276,7 @@ async def api_create_wallet(
)
-@wallet_router.get("/onchain", response_model_exclude={"adminkey", "inkey"})
+@wallet_router.get("/onchain", response_model_exclude={"adminkey", "inkey", "user"})
async def api_wallets_retrieve(
network: Literal["Mainnet", "Testnet", "Testnet4"] | None = Query(None),
auth: OnchainAuth = Depends(require_onchain_read),
@@ -289,7 +289,7 @@ async def api_wallets_retrieve(
return wallet
-@wallet_router.post("/onchain", response_model_exclude={"adminkey", "inkey"})
+@wallet_router.post("/onchain", response_model_exclude={"adminkey", "inkey", "user"})
async def api_wallet_create_or_update(
data: CreateOnchainWallet,
auth: OnchainAuth = Depends(require_onchain_admin),
### tests/api/test_onchain_wallet.py
@@ -80,6 +80,7 @@ async def add_watch(client, headers, single_path=False):
},
)
assert response.status_code == 200, response.text
+ assert "user" not in response.json()
return response.json()
@@ -105,11 +106,13 @@ async def setup(kind, api_headers):
assert sorted(r.status_code for r in results) == [200, 409]
rejected = next(r for r in results if r.status_code == 409)
assert "already configured" in rejected.json()["detail"]
- accounts = await http_client.get("/api/v1/wallet/onchain", headers=headers)
+ accounts = await http_client.get(
+ "/api/v1/wallet/onchain", headers={"X-API-KEY": wallet.inkey}
+ )
assert accounts.status_code == 200
account = accounts.json()
assert account["id"] == wallet.id
- assert not {"adminkey", "inkey", "onchain_encrypted_seed"} & account.keys()
+ assert not {"adminkey", "inkey", "user", "onchain_encrypted_seed"} & account.keys()
stored_keys = await db.fetchall(
"""SELECT id FROM wallets WHERE id = :wallet
AND onchain_encrypted_seed IS NOT NULL""",
@@ -161,7 +164,7 @@ async def test_onchain_api_ownership_recovery_and_network(http_client, onchain_w
assert response.status_code == 200, response.text
account = response.json()
assert account["id"] == wallet.id
- assert not {"adminkey", "inkey", "onchain_encrypted_seed"} & account.keys()
+ assert not {"adminkey", "inkey", "user", "onchain_encrypted_seed"} & account.keys()
assert "mnemonic" not in response.text and "encrypted_seed" not in response.text
account_id = account["id"]
path = f"/api/v1/onchain/hot-wallet/{account_id}/backup"
@@ -177,9 +180,9 @@ async def test_onchain_api_ownership_recovery_and_network(http_client, onchain_w
assert len(export.json()["mnemonic"].split()) == 24
receive = f"/api/v1/onchain/address/{account_id}"
assert (await http_client.get(receive, headers=headers)).status_code == 409
- assert (
- await http_client.post(path + "/confirm", headers=headers)
- ).status_code == 200
+ confirmed = await http_client.post(path + "/confirm", headers=headers)
+ assert confirmed.status_code == 200
+ assert "user" not in confirmed.json()
responses = await asyncio.gather(
*(
http_client.get(receive, headers={"X-API-KEY": wallet.inkey})
### tests/api/test_wallet_api.py
@@ -163,6 +163,7 @@ async def test_wallet_api_paginated_update_reset_and_store_paylinks(
json={"icon": "bolt", "color": "amber", "pinned": True},
)
assert updated.status_code == 200
+ assert "user" not in updated.json()
assert updated.json()["extra"]["icon"] == "bolt"
assert updated.json()["extra"]["color"] == "amber"
assert updated.json()["extra"]["pinned"] is TrueWhy this scored 52/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.