mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Detect PID loops in api auth
This commit is contained in:
parent
f7fbf40cf9
commit
625b79e3b3
1 changed files with 10 additions and 0 deletions
|
@ -112,6 +112,7 @@ func authenticateAPIRequest(ctx context.Context, pktInfo *packet.Info) (retry bo
|
|||
return true, fmt.Errorf("failed to get process: %s", err)
|
||||
}
|
||||
originalPid := proc.Pid
|
||||
var previousPid int
|
||||
|
||||
// go up up to two levels, if we don't match
|
||||
for i := 0; i < 5; i++ {
|
||||
|
@ -130,11 +131,20 @@ func authenticateAPIRequest(ctx context.Context, pktInfo *packet.Info) (retry bo
|
|||
procsChecked = append(procsChecked, proc.Path)
|
||||
|
||||
if i < 4 {
|
||||
// save previous PID
|
||||
previousPid = proc.Pid
|
||||
|
||||
// get parent process
|
||||
proc, err = process.GetOrFindProcess(ctx, proc.ParentPid)
|
||||
if err != nil {
|
||||
return true, fmt.Errorf("failed to get process: %s", err)
|
||||
}
|
||||
|
||||
// abort if we are looping
|
||||
if proc.Pid == previousPid {
|
||||
// this also catches -1 pid loops
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue