Disallow subscribing to /docs
This commit is contained in:
parent
9a56c24dbe
commit
b437a87266
2 changed files with 16 additions and 2 deletions
|
@ -83,6 +83,7 @@ var (
|
||||||
|
|
||||||
staticRegex = regexp.MustCompile(`^/static/.+`)
|
staticRegex = regexp.MustCompile(`^/static/.+`)
|
||||||
docsRegex = regexp.MustCompile(`^/docs(|/.*)$`)
|
docsRegex = regexp.MustCompile(`^/docs(|/.*)$`)
|
||||||
|
disallowedTopics = []string{"docs", "static"}
|
||||||
|
|
||||||
//go:embed "index.gohtml"
|
//go:embed "index.gohtml"
|
||||||
indexSource string
|
indexSource string
|
||||||
|
@ -496,6 +497,9 @@ func (s *Server) topicsFromIDs(ids ...string) ([]*topic, error) {
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
topics := make([]*topic, 0)
|
topics := make([]*topic, 0)
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
|
if util.InStringList(disallowedTopics, id) {
|
||||||
|
return nil, errHTTPBadRequest
|
||||||
|
}
|
||||||
if _, ok := s.topics[id]; !ok {
|
if _, ok := s.topics[id]; !ok {
|
||||||
if len(s.topics) >= s.config.GlobalTopicLimit {
|
if len(s.topics) >= s.config.GlobalTopicLimit {
|
||||||
return nil, errHTTPTooManyRequests
|
return nil, errHTTPTooManyRequests
|
||||||
|
|
10
util/util.go
10
util/util.go
|
@ -23,6 +23,16 @@ func FileExists(filename string) bool {
|
||||||
return stat != nil
|
return stat != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InStringList returns true if needle is contained in haystack
|
||||||
|
func InStringList(haystack []string, needle string) bool {
|
||||||
|
for _, s := range haystack {
|
||||||
|
if s == needle {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// RandomString returns a random string with a given length
|
// RandomString returns a random string with a given length
|
||||||
func RandomString(length int) string {
|
func RandomString(length int) string {
|
||||||
randomMutex.Lock() // Who would have thought that random.Intn() is not thread-safe?!
|
randomMutex.Lock() // Who would have thought that random.Intn() is not thread-safe?!
|
||||||
|
|
Loading…
Reference in a new issue