Add insecure sources logic

This commit is contained in:
Alex X
2025-11-11 17:33:15 +03:00
parent c10a06d199
commit 2133f5323c
5 changed files with 25 additions and 12 deletions
+1
View File
@@ -42,4 +42,5 @@ func Init() {
return string(b), nil return string(b), nil
}) })
streams.MarkInsecure("echo")
} }
+1
View File
@@ -56,6 +56,7 @@ func Init() {
}) })
streams.HandleFunc("exec", execHandle) streams.HandleFunc("exec", execHandle)
streams.MarkInsecure("exec")
log = app.GetLogger("exec") log = app.GetLogger("exec")
} }
+1
View File
@@ -25,4 +25,5 @@ func Init() {
return url, nil return url, nil
}) })
streams.MarkInsecure("expr")
} }
+22
View File
@@ -2,6 +2,7 @@ package streams
import ( import (
"errors" "errors"
"regexp"
"strings" "strings"
"github.com/AlexxIT/go2rtc/pkg/core" "github.com/AlexxIT/go2rtc/pkg/core"
@@ -95,3 +96,24 @@ func GetConsumer(url string) (core.Consumer, func(), error) {
return nil, nil, errors.New("streams: unsupported scheme: " + url) return nil, nil, errors.New("streams: unsupported scheme: " + url)
} }
var insecure = map[string]bool{}
func MarkInsecure(scheme string) {
insecure[scheme] = true
}
var sanitize = regexp.MustCompile(`\s`)
func Validate(source string) error {
// TODO: Review the entire logic of insecure sources
if i := strings.IndexByte(source, ':'); i > 0 {
if insecure[source[:i]] {
return errors.New("streams: source from insecure producer")
}
}
if sanitize.MatchString(source) {
return errors.New("streams: source with spaces may be insecure")
}
return nil
}
-12
View File
@@ -1,9 +1,7 @@
package streams package streams
import ( import (
"errors"
"net/url" "net/url"
"regexp"
"sync" "sync"
"time" "time"
@@ -50,16 +48,6 @@ func Init() {
}) })
} }
var sanitize = regexp.MustCompile(`\s`)
// Validate - not allow creating dynamic streams with spaces in the source
func Validate(source string) error {
if sanitize.MatchString(source) {
return errors.New("streams: invalid dynamic source")
}
return nil
}
func New(name string, sources ...string) *Stream { func New(name string, sources ...string) *Stream {
for _, source := range sources { for _, source := range sources {
if Validate(source) != nil { if Validate(source) != nil {