mirror of
https://github.com/sigcn/pg.git
synced 2025-09-26 19:01:11 +08:00
peermap/api: fix privilege escalation during token refresh
This commit is contained in:
8
langs/ifelse.go
Normal file
8
langs/ifelse.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package langs
|
||||
|
||||
func IfElse[T any](cond bool, v1, v2 T) T {
|
||||
if cond {
|
||||
return v1
|
||||
}
|
||||
return v2
|
||||
}
|
@@ -59,7 +59,7 @@ func (a *ApiV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if time.Until(time.Unix(secret.Deadline, 0)) <
|
||||
a.Config.SecretValidityPeriod-a.Config.SecretRotationPeriod {
|
||||
if newSecret, err := a.Grant(secret.Network, "PG_ADM"); err == nil {
|
||||
if newSecret, err := a.Grant(secret.Network, langs.IfElse(secret.Admin, "PG_ADM", "")); err == nil {
|
||||
b, _ := json.Marshal(newSecret)
|
||||
w.Header().Add("X-Set-Token", string(b))
|
||||
}
|
||||
|
Reference in New Issue
Block a user