Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
956 B

9 years ago
  1. package main
  2. import (
  3. "net/http"
  4. "net/url"
  5. )
  6. // Do a strict referrer check, matching against both the Origin header (if
  7. // present) and the Referrer header. If a list of headers is specified, then
  8. // Referrer checking will be skipped if any of those headers are present.
  9. func strictReferrerCheck(r *http.Request, prefix string, whitelistHeaders []string) bool {
  10. p, _ := url.Parse(prefix)
  11. // if there's an Origin header, check it and skip other checks
  12. if origin := r.Header.Get("Origin"); origin != "" {
  13. u, _ := url.Parse(origin)
  14. return sameOrigin(u, p)
  15. }
  16. for _, header := range whitelistHeaders {
  17. if r.Header.Get(header) != "" {
  18. return true
  19. }
  20. }
  21. referrer := r.Header.Get("Referer")
  22. u, _ := url.Parse(referrer)
  23. return sameOrigin(u, p)
  24. }
  25. // Check if two URLs have the same origin
  26. func sameOrigin(u1, u2 *url.URL) bool {
  27. // host also contains the port if one was specified
  28. return (u1.Scheme == u2.Scheme && u1.Host == u2.Host)
  29. }