安全: 多用户环境下令牌回退路径冲突 (cap_portal.rs) #3

Closed
opened 2026-06-04 20:58:24 +08:00 by dailz · 0 comments
Owner

位置

src/cap_portal.rs:249-253

严重性

🟡

问题描述

dirs::cache_dir() 返回 None 时,回退到 /tmp/wl-webrtc/portal-restore-token/tmp 是全局共享的临时目录,多用户运行时路径相同,导致:

  1. 用户 A 可读取用户 B 的恢复令牌
  2. 不同用户的令牌相互覆盖

另外,/tmp 中的文件在系统重启后会被清理,使令牌无法持久化,违背了 PersistMode::ExplicitlyRevoked 的设计意图。

建议修复

回退路径应包含 UID 以保证用户隔离:

fn token_path() -> PathBuf {
    let base = dirs::cache_dir().unwrap_or_else(|| {
        let uid = unsafe { libc::getuid() };
        PathBuf::from(format!("/tmp/wl-webrtc-{uid}"))
    });
    base.join("portal-restore-token")
}
## 位置 `src/cap_portal.rs:249-253` ## 严重性 🟡 中 ## 问题描述 当 `dirs::cache_dir()` 返回 `None` 时,回退到 `/tmp/wl-webrtc/portal-restore-token`。`/tmp` 是全局共享的临时目录,多用户运行时路径相同,导致: 1. 用户 A 可读取用户 B 的恢复令牌 2. 不同用户的令牌相互覆盖 另外,`/tmp` 中的文件在系统重启后会被清理,使令牌无法持久化,违背了 `PersistMode::ExplicitlyRevoked` 的设计意图。 ## 建议修复 回退路径应包含 UID 以保证用户隔离: ```rust fn token_path() -> PathBuf { let base = dirs::cache_dir().unwrap_or_else(|| { let uid = unsafe { libc::getuid() }; PathBuf::from(format!("/tmp/wl-webrtc-{uid}")) }); base.join("portal-restore-token") } ```
dailz closed this issue 2026-06-06 11:45:17 +08:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dailz/wl-webrtc#3