Add stream source validation for dynamic streams
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package streams
|
package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -49,9 +50,16 @@ func Get(name string) *Stream {
|
|||||||
|
|
||||||
var sanitize = regexp.MustCompile(`\s`)
|
var sanitize = regexp.MustCompile(`\s`)
|
||||||
|
|
||||||
func New(name string, source string) *Stream {
|
// Validate - not allow creating dynamic streams with spaces in the source
|
||||||
// not allow creating dynamic streams with spaces in the source
|
func Validate(source string) error {
|
||||||
if sanitize.MatchString(source) {
|
if sanitize.MatchString(source) {
|
||||||
|
return errors.New("streams: invalid dynamic source")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(name string, source string) *Stream {
|
||||||
|
if Validate(source) != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,13 +211,17 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// with dst - redirect source to dst
|
// with dst - redirect source to dst
|
||||||
if dst := query.Get("dst"); dst != "" {
|
if dst := query.Get("dst"); dst != "" {
|
||||||
if stream := Get(dst); stream != nil {
|
if stream := Get(dst); stream != nil {
|
||||||
if err := stream.Play(src); err != nil {
|
if err := Validate(src); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
} else if err = stream.Play(src); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
} else {
|
||||||
api.ResponseJSON(w, stream)
|
api.ResponseJSON(w, stream)
|
||||||
}
|
}
|
||||||
} else if stream = Get(src); stream != nil {
|
} else if stream = Get(src); stream != nil {
|
||||||
if err := stream.Publish(dst); err != nil {
|
if err := Validate(dst); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
} else if err = stream.Publish(dst); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user