Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/dashboard/services/config_service.py" line_range="531" />
<code_context>
+ return response_config
+
+
+def _restore_redacted_totp_secret(config: dict, current_config: dict) -> None:
+ """Restore the server-side secret before comparing a redacted update."""
+ totp = config.get("dashboard", {}).get("totp")
+ if not isinstance(totp, dict):
+ return
</code_context>
<issue_to_address>
**issue (bug_risk):** `config.get("dashboard", {}).get("totp")` raises `AttributeError` when an update payload contains `"dashboard": None` or another non-dict value, so the API returns an unhandled server error instead of applying normal validation or returning a controlled client error.
**Triggers:** When a malformed or partially populated config payload supplies a non-dict `dashboard` value.
**Suggested fix:** Read `dashboard = config.get("dashboard")` first and return unless it is a dict before accessing `dashboard.get("totp")`.
```suggestion
dashboard = config.get("dashboard")
if not isinstance(dashboard, dict):
return
totp = dashboard.get("totp")
```
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and this changes how an active TOTP credential is exposed through configuration responses and how submitted configuration is persisted. If the redaction or restoration is wrong, the secret could be disclosed or replaced, and reverting would not undo any credential exposure or authentication disruption that already occurred.
Blocking findings: astrbot/dashboard/services/config_service.py:531
|
|
||
| def _restore_redacted_totp_secret(config: dict, current_config: dict) -> None: | ||
| """Restore the server-side secret before comparing a redacted update.""" | ||
| totp = config.get("dashboard", {}).get("totp") |
There was a problem hiding this comment.
issue (bug_risk): config.get("dashboard", {}).get("totp") raises AttributeError when an update payload contains "dashboard": None or another non-dict value, so the API returns an unhandled server error instead of applying normal validation or returning a controlled client error.
Triggers: When a malformed or partially populated config payload supplies a non-dict dashboard value.
Suggested fix: Read dashboard = config.get("dashboard") first and return unless it is a dict before accessing dashboard.get("totp").
| totp = config.get("dashboard", {}).get("totp") | |
| dashboard = config.get("dashboard") | |
| if not isinstance(dashboard, dict): | |
| return | |
| totp = dashboard.get("totp") |
Motivation
The dashboard config API returned the active TOTP secret after setup. An authenticated user could copy it from the manage dialog or provisioning QR and clone the authenticator. Fixes #8599.
Changes
Testing
uv run pytest tests/test_dashboard.py -q(89 passed, 1 skipped)uv run ruff format ... && uv run ruff check ...cd dashboard && npx pnpm@10 run typecheckgit diff --checkSummary by Sourcery
Protect active dashboard TOTP credentials while allowing non-security configuration changes to be saved safely.
Bug Fixes:
Enhancements:
Tests: