Skip to content

Commit 2133f53

Browse files
committed
Add insecure sources logic
1 parent c10a06d commit 2133f53

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

internal/echo/echo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ func Init() {
4242

4343
return string(b), nil
4444
})
45+
streams.MarkInsecure("echo")
4546
}

internal/exec/exec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func Init() {
5656
})
5757

5858
streams.HandleFunc("exec", execHandle)
59+
streams.MarkInsecure("exec")
5960

6061
log = app.GetLogger("exec")
6162
}

internal/expr/expr.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ func Init() {
2525

2626
return url, nil
2727
})
28+
streams.MarkInsecure("expr")
2829
}

internal/streams/handlers.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package streams
22

33
import (
44
"errors"
5+
"regexp"
56
"strings"
67

78
"github.com/AlexxIT/go2rtc/pkg/core"
@@ -95,3 +96,24 @@ func GetConsumer(url string) (core.Consumer, func(), error) {
9596

9697
return nil, nil, errors.New("streams: unsupported scheme: " + url)
9798
}
99+
100+
var insecure = map[string]bool{}
101+
102+
func MarkInsecure(scheme string) {
103+
insecure[scheme] = true
104+
}
105+
106+
var sanitize = regexp.MustCompile(`\s`)
107+
108+
func Validate(source string) error {
109+
// TODO: Review the entire logic of insecure sources
110+
if i := strings.IndexByte(source, ':'); i > 0 {
111+
if insecure[source[:i]] {
112+
return errors.New("streams: source from insecure producer")
113+
}
114+
}
115+
if sanitize.MatchString(source) {
116+
return errors.New("streams: source with spaces may be insecure")
117+
}
118+
return nil
119+
}

internal/streams/streams.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package streams
22

33
import (
4-
"errors"
54
"net/url"
6-
"regexp"
75
"sync"
86
"time"
97

@@ -50,16 +48,6 @@ func Init() {
5048
})
5149
}
5250

53-
var sanitize = regexp.MustCompile(`\s`)
54-
55-
// Validate - not allow creating dynamic streams with spaces in the source
56-
func Validate(source string) error {
57-
if sanitize.MatchString(source) {
58-
return errors.New("streams: invalid dynamic source")
59-
}
60-
return nil
61-
}
62-
6351
func New(name string, sources ...string) *Stream {
6452
for _, source := range sources {
6553
if Validate(source) != nil {

0 commit comments

Comments
 (0)