Skip to content

Commit 9c4ea61

Browse files
committed
fix: enforce polkit auth and prevent chpasswd injection
1. SetPassword now requires polkitActionUserAdministration instead of empty action, fixing a permission bypass 2. ModifyPasswd rejects password hashes containing \n\r: to prevent chpasswd stdin injection Log: password change requires admin authentication Influence: 1. non-admin user should be denied when calling DBus SetPassword 2. password hash containing newline or colon should return error fix: 修改密码需鉴权并防止 chpasswd 注入 1. SetPassword 改为需要 polkitActionUserAdministration 鉴权, 修复空 action 导致的权限绕过 2. ModifyPasswd 拒绝包含 \n\r: 的密码哈希, 防止通过 chpasswd stdin 注入额外记录 Log: 修改密码需要管理员鉴权,防止未授权修改 Influence: 1. 非管理员用户尝试通过 DBus SetPassword 修改密码应被拒绝 2. 验证密码哈希包含换行或冒号时返回错误
1 parent 65548c9 commit 9c4ea61

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

accounts1/user_ifc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ func (u *User) SetPassword(sender dbus.Sender, password string) *dbus.Error {
122122
if password == "" {
123123
return nil
124124
}
125-
126-
err := u.checkAuth(sender, false, "")
125+
// 修改密码,一律需要鉴权管理员
126+
err := u.checkAuth(sender, false, polkitActionUserAdministration)
127127
if err != nil {
128128
logger.Debug("[SetPassword] access denied:", err)
129129
return dbusutil.ToError(err)

accounts1/users/prop.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ func ModifyPasswd(words, username string) error {
161161
if len(words) == 0 {
162162
return errInvalidParam
163163
}
164+
// 防止命令注入
165+
if strings.ContainsAny(words, "\n\r") {
166+
return errInvalidParam
167+
}
164168

165169
cmd := exec.Command(pwdCmdModify, "-e")
166170
input := fmt.Sprintf("%s:%s\n", username, words)

0 commit comments

Comments
 (0)