Commit 40cf62e
fix: auth middleware 視空字串 token 為 disabled(對齊 compose env fallback)
commit a995f49 的 bug:docker-compose.yml 寫 `MH_API_TOKEN: ${MH_API_TOKEN:-}`,
host env 未設時 compose 展成空字串傳進 container,pydantic 讀 env 把
api_token 設成 ""(不是 None)。middleware 的 `is None` 判斷失效,誤開啟 auth。
今日 deploy 到 mini 時立刻踩到——container 健康但所有 /v1/memory/* 回 401
"missing bearer token",因為 client(skills)還沒帶 header。
修:middleware 改用 `if not active_settings.api_token:`,None 和 "" 都 bypass。
補 test_auth_empty_string_token_also_disables_auth 明確守住這 regression。
ADR-0007 描述的「未設即 bypass」行為靠這個判斷站住。
Directive: 不用 pydantic field_validator 把 "" 轉 None — middleware 一條判斷夠,
加 validator 是多層間接
Rejected: 改 docker-compose.yml 不透傳 MH_API_TOKEN 空值 | 要分情境定義
service env,比 middleware 一個 `not` 判斷複雜得多
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent a995f49 commit 40cf62e
2 files changed
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
655 | 655 | | |
656 | 656 | | |
657 | 657 | | |
658 | | - | |
659 | | - | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
660 | 662 | | |
661 | 663 | | |
662 | 664 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
30 | 42 | | |
31 | 43 | | |
32 | 44 | | |
| |||
0 commit comments