Skip to content

Commit

Permalink
Refactor disallowed domains in HTTP service
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh committed Jul 9, 2018
1 parent 90078ff commit c457210
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion interfacer/src/browsh/raw_text_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"crypto/rand"
"io"
"time"
"regexp"

"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/store/memory"
Expand Down Expand Up @@ -83,7 +84,7 @@ func handleHTTPServerRequest(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("Cache-Control", "public, max-age=600")
if (strings.Contains(urlForBrowsh, "mail.google.com")) {
if (isDisallowedURL(urlForBrowsh)) {
http.Redirect(w, r, "/", 301)
return
}
Expand Down Expand Up @@ -111,6 +112,11 @@ func handleHTTPServerRequest(w http.ResponseWriter, r *http.Request) {
waitForResponse(rawTextRequestID, w)
}

func isDisallowedURL(urlForBrowsh string) bool {
r, _ := regexp.Compile("[mail|accounts].google.com")
return r.MatchString(urlForBrowsh)
}

func isProductionHTTP(r *http.Request) bool {
if (strings.Contains(r.Host, "brow.sh")) {
return r.Header.Get("X-Forwarded-Proto") == "http"
Expand Down

0 comments on commit c457210

Please sign in to comment.