mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Merge pull request #1469 from safing/feature/allowed-clients
Add support for --allowed-clients parameter to whitelist binaries that are allowed to talk to the Portmaster API
This commit is contained in:
commit
3a55d902a2
2 changed files with 26 additions and 1 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -164,6 +165,12 @@ func authenticateAPIRequest(ctx context.Context, pktInfo *packet.Info) (retry bo
|
||||||
default: // normal process
|
default: // normal process
|
||||||
// Check if the requesting process is in database root / updates dir.
|
// Check if the requesting process is in database root / updates dir.
|
||||||
if realPath, err := filepath.EvalSymlinks(proc.Path); err == nil {
|
if realPath, err := filepath.EvalSymlinks(proc.Path); err == nil {
|
||||||
|
|
||||||
|
// check if the client has been allowed by flag
|
||||||
|
if slices.Contains(allowedClients, realPath) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(realPath, authenticatedPath) {
|
if strings.HasPrefix(realPath, authenticatedPath) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package firewall
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/safing/portbase/config"
|
"github.com/safing/portbase/config"
|
||||||
|
@ -16,7 +18,21 @@ import (
|
||||||
"github.com/safing/portmaster/spn/captain"
|
"github.com/safing/portmaster/spn/captain"
|
||||||
)
|
)
|
||||||
|
|
||||||
var module *modules.Module
|
type stringSliceFlag []string
|
||||||
|
|
||||||
|
func (ss *stringSliceFlag) String() string {
|
||||||
|
return strings.Join(*ss, ":")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ss *stringSliceFlag) Set(value string) error {
|
||||||
|
*ss = append(*ss, filepath.Clean(value))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
module *modules.Module
|
||||||
|
allowedClients stringSliceFlag
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
module = modules.Register("filter", prep, start, stop, "core", "interception", "intel", "netquery")
|
module = modules.Register("filter", prep, start, stop, "core", "interception", "intel", "netquery")
|
||||||
|
@ -28,6 +44,8 @@ func init() {
|
||||||
"config:filter/",
|
"config:filter/",
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
flag.Var(&allowedClients, "allowed-clients", "A list of binaries that are allowed to connect to the Portmaster API")
|
||||||
}
|
}
|
||||||
|
|
||||||
func prep() error {
|
func prep() error {
|
||||||
|
|
Loading…
Add table
Reference in a new issue