Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
fix #22: check cookie flags
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed May 11, 2018
1 parent d91eea3 commit 2eb7ea5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Server struct {
// GetTrackerInstructionV1 is responsible for `GET /api/v1/tracker/instruction` request handling.
func (s *Server) GetTrackerInstructionV1(rw http.ResponseWriter, req *http.Request) {
cookie, err := req.Cookie(MarkerKey)
if err != nil {
cookie = &http.Cookie{Name: MarkerKey}
if err != nil || !cookie.HttpOnly || !cookie.Secure {
cookie = &http.Cookie{Name: MarkerKey, Secure: true, HttpOnly: true}
}

response := s.service.HandleTrackerInstructionV1(tracker.InstructionRequest{EncryptedMarker: cookie.Value})
Expand All @@ -49,7 +49,6 @@ func (s *Server) GetTrackerInstructionV1(rw http.ResponseWriter, req *http.Reque
}

cookie.MaxAge, cookie.Path, cookie.Value = 0, "/", response.EncryptedMarker
cookie.Secure, cookie.HttpOnly = true, true
http.SetCookie(rw, cookie)
rw.Header().Set("Content-Type", "application/javascript")
rw.WriteHeader(http.StatusOK)
Expand Down Expand Up @@ -82,6 +81,13 @@ func (s *Server) PostTrackerFingerprintV1(rw http.ResponseWriter, req *http.Requ
req.Body.Close()
return
}
if !cookie.HttpOnly || !cookie.Secure {
// issue #22: prevent cookie manipulation
log.Printf("\n\n[CRITICAL] cookie is not safe, skip this request (%+v)\n\n", *cookie)
io.Copy(ioutil.Discard, req.Body)
req.Body.Close()
return
}

defer req.Body.Close()
request := tracker.FingerprintRequest{EncryptedMarker: cookie.Value, Header: req.Header}
Expand Down

0 comments on commit 2eb7ea5

Please sign in to comment.